简体   繁体   English

'numpy.ndarray' object 没有属性 'D'

[英]'numpy.ndarray' object has no attribute 'D'

import numpy as np
rowlist = np.array([[0, 2, 3, 4, 5], [0, 0, 0, 3, 2], [1, 2, 3, 4, 5], [0, 0, 0, 6, 7], [0, 0, 0, 9, 9]])

new_rowlist = []
rows_left = set(range(len(rowlist)))
col_label_list = sorted(rowlist[0].D, key=hash)

for c in col_label_list:
    rows_with_non_zero = [ r for r in rows_left if rowlist[r][c] != 0 ]
    if rows_with_non_zero != []:
        pivot = rows_with_non_zero[0]
        new_rowlist.append(rowlist[pivot])
        rows_left.remove(pivot)

for r in new_rowlist:
    print(r)

So i'm following the Coding the Matrix by Philip Klein book lessons and on one of the chapter on Gaussian Elimination, this keeps erroring 'numpy.ndarray' object has no attribute 'D' What I wanted was to be able to sort the matrix called rowlist.所以我正在关注 Philip Klein 的 Coding the Matrix 书籍课程和关于高斯消除的一章,这一直出错 'numpy.ndarray' object 没有属性 'D' 我想要的是能够对矩阵进行排序称为行列表。 Any idea how to overcome this?知道如何克服这个问题吗? im doing this on jupyter notebook if it is of any help Thanks in advance!如果有任何帮助,我会在 jupyter notebook 上执行此操作提前谢谢!

There is a typo.有一个错字。 There is no rowlist[0].D , change the line to the following没有rowlist[0].D ,改行如下

col_label_list = sorted(rowlist[0], key=hash)

Also, maybe from next time as a learning process, try and debug a code yourself by locating which line is causing the error (if you read the error message properly).此外,也许从下一次作为一个学习过程开始,尝试通过定位导致错误的行来自己调试代码(如果您正确阅读了错误消息)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM