Python错误问题

xiaoxiao2021-02-28  25

IndexError: invalid index to scalar variable.

生成了一个长度为10的一维数组,然后使用reshape转换成2x5的矩阵,但是在取矩阵值的时候出现索引错误

import numpy as np a = np.arange(0,10) a.reshape(2,5) a[1][1]

原因:数组a经过reshape后,a中的内容没有变,需要重新赋值

import numpy as np a = np.arange(0,10) b = a.reshape(2,5) b[1][1] 6输出了正确值
转载请注明原文地址: https://www.6miu.com/read-2622210.html

最新回复(0)