我对python / numpy很新,并不完全清楚它。
我一直在尝试实现一种算法,并且在尝试使用其转置获取数组的点积时陷入某一点。我得到的错误是这个
TypeError:只能将整数标量数组转换为标量索引。
以下是我的参考代码。
import pandas as pd
import numpy as np
dataset=pd.read_csv('SCLC_study_output_filtered_2.csv',header=0,delimiter=",")
#forming the first class
class_1 = dataset.iloc[0:20,1:20].values
#forming the second class
class_2 = dataset.iloc[20:41,1:20].values
mean_c1 = np.mean(class_1, axis=0)
#Taking mean of class 2
mean_c2 = np.mean(class_2, axis=0)
mean_classes =[mean_c1,mean_c2]
#Calculating S-within for class-1
scatter_within_c1 = np.zeros((19,19))
for i in range(0,20):
for col in class_1:
col, m = col.reshape(19,1), mean_c1.reshape(19,1)
sub = np.subtract(col,m)
scatter_within_c1 += np.prod(sub,np.transpose(sub))
答案 0 :(得分:1)
override init () { super.init(); // necessary otherwise next line is an error pluginInitialize(); } override func pluginInitialize() { players = [:]; }
返回给定轴上的数组元素的乘积。
numpy.prod(a, axis=None, dtype=None, out=None, keepdims=<class numpy._globals._NoValue>)
函数不适用于两个不同的数组。对于点积,您可以使用np.dot()
function或等效地,
ndarray.dot()
method:
np.prod()