【发布时间】:2015-03-02 05:45:24
【问题描述】:
我在 python 中遇到了最奇怪的属性错误,我似乎在网上找不到任何关于它的信息。 我正在尝试对矩阵 y 的所有列的元素求和,并将它们保存在一个新矩阵中。 y 是 1. 和 0. 的 1063 x 1063 单位矩阵。 mat 是一个 70000 x 1063 的稀疏矩阵
mat = scipy.sparse.rand(70000, 1063, density=0.01, format='coo', dtype=None, random_state=None)
mat.shape
给我:
(70000, 1063)
现在我创建 y,一个 1063 x 1063 的单位矩阵:
y = np.matlib.identity(1063)
ind = np.nonzero((mat.sum(axis=0) < 20))
y[ind, :] = 0 # replace element at given index with 0
x = np.sum(y, axis=1) # here i want to count the elements of all columns of y
我收到关于最后一行的以下错误:
AttributeError: 'numpy.ndarray' object has no attribute '_collapse'
我迷路了。关于如何解决这个问题的任何想法?
【问题讨论】:
-
你在ndarray中传递什么类型的数据,
y? -
y 是一个浮点矩阵
-
type(y)给了什么? -
哦,它给出了:numpy.matrixlib.defmatrix.matrix
-
什么形状?
y.shape最好提供一个最小的非工作示例。 How to ask
标签: python numpy matrix pandas attributeerror