【发布时间】:2021-09-15 00:33:18
【问题描述】:
我对 numpy 数组有疑问,我不明白我做错了什么。我需要用随机整数(非零)创建一个 100x100 矩阵,最后一行应该是前面所有行的组合。这是我的代码:
non_zero_m = np.random.randint(0,10,(99,100))
arr = non_zero_m.sum(axis=0)
singular_m = np.concatenate((non_zero_m, arr))
ValueError: all the input arrays must have same number of dimensions, but the array at index 0 has 2 dimension(s) and the array at index 1 has 1 dimension(s)
我不明白为什么 python 显示数组有不同的维度
【问题讨论】:
-
什么是
arr.shape?重读np.concatenate文档。也看np.vstack