我有“2006-2016年IMDB数据”的数据框,在Kaggle站点:https://www.kaggle.com/PromptCloudHQ/imdb-data。
我已将其作为numpy数组,但当我要将其中两行的内积赋给numpy.float64变量时,它会给出以下错误:sim[i][1] = np.inner(vec[i],vec[1])
TypeError: 'numpy.float64' object does not support item assignment
这是我的代码:X = trainset.drop(['Description', 'Runtime','Director','Title', 'ID'], axis=1)
X.Revenue = X.Revenue.fillna(X.Revenue.mean())
X.Metascore= X.Metascore.fillna(X.Revenue.min())
features = ['Genre','Actors']
for f in features:
X_dummy = X[f].str.get_dummies(',').add_prefix(f + '.')
X = X.drop([f], axis = 1)
X = pd.concat((X, X_dummy), axis = 1)
vec = np.ones((1000,2422), dtype=np.uint8)
vec = X.values
sim = np.ones((1000,1), dtype=np.float64)
for i in range (1,1000):
sim[i][1] = np.inner(vec[i],vec[1])
当我得到这种内部产品的类型时,它正好给出了这种类型:>>chi = np.inner(vec[0],vec[0])
>>print(type(chi))