![](/img/trans.png)
[英]TypeError: only integer scalar arrays can be converted to a scalar index
[英]Error: TypeError: only integer scalar arrays can be converted to a scalar index
我是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))
查看文档中的np.prod()
:
numpy.prod(a, axis=None, dtype=None, out=None, keepdims=<class numpy._globals._NoValue>)
返回给定轴上数组元素的乘积。
np.prod()
函数不适用于两个不同的数组。 对于点积,可以使用np.dot()
函数或等效地使用ndarray.dot()
方法 :
>>> A = np.array([1, 2, 3, 4, 5])
>>> np.dot(A, A)
55
>>> A.dot(A)
55
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.