Я написал довольно простой код, чтобы попрактиковаться в использовании функции matmul, и хотя она настолько проста, насколько это возможно, она не работает.
import numpy as np
import pandas as pd
df = pd.DataFrame(np.random.randint(0,100,size=(4999, 1128)))
tab = np.random.rand(1128)
np.matmul(df,tab)
Выдает следующие ошибки:
Traceback (most recent call last):
File "/Users/jk/Documents/programowanie19/movie_recommendation/venv/lib/python3.7/site-packages/pandas/core/internals/managers.py", line 1651, in create_block_manager_from_blocks
placement=slice(0, len(axes[0])))]
File "/Users/jk/Documents/programowanie19/movie_recommendation/venv/lib/python3.7/site-packages/pandas/core/internals/blocks.py", line 3095, in make_block
return klass(values, ndim=ndim, placement=placement)
File "/Users/jk/Documents/programowanie19/movie_recommendation/venv/lib/python3.7/site-packages/pandas/core/internals/blocks.py", line 87, in __init__
'{mgr}'.format(val=len(self.values), mgr=len(self.mgr_locs)))
ValueError: Wrong number of items passed 1, placement implies 1128
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test2.py", line 9, in <module>
np.matmul(df,tab)
File "/Users/jk/Documents/programowanie19/movie_recommendation/venv/lib/python3.7/site-packages/pandas/core/generic.py", line 1909, in __array_wrap__
return self._constructor(result, **d).__finalize__(self)
File "/Users/jk/Documents/programowanie19/movie_recommendation/venv/lib/python3.7/site-packages/pandas/core/frame.py", line 424, in __init__
copy=copy)
File "/Users/jk/Documents/programowanie19/movie_recommendation/venv/lib/python3.7/site-packages/pandas/core/internals/construction.py", line 167, in init_ndarray
return create_block_manager_from_blocks([values], [columns, index])
File "/Users/jk/Documents/programowanie19/movie_recommendation/venv/lib/python3.7/site-packages/pandas/core/internals/managers.py", line 1660, in create_block_manager_from_blocks
construction_error(tot_items, blocks[0].shape[1:], axes, e)
File "/Users/jk/Documents/programowanie19/movie_recommendation/venv/lib/python3.7/site-packages/pandas/core/internals/managers.py", line 1691, in construction_error
passed, implied))
ValueError: Shape of passed values is (4999, 1), indices imply (4999, 1128)
Размеры двух матриц должны совпадать - df равно (4999,1128) , а tab равно (1128,1) . Кто-нибудь знает в чем здесь проблема?