繁体   English   中英

如何通过具有单例尺寸的1d数组在python中索引没有单例尺寸的1d数组?

[英]How to index 1d array without singleton dimension in python by 1d array with singleton dimension?

在python中索引一维数组的变体的过程是什么?

例如,考虑以下示例:

a = np.ones(100)
b = np.ones(100, 1)
a[b > 0]
IndexError                                Traceback (most recent call last)
<ipython-input-14-05e3ddce24c9> in <module>()
----> 1 a[b == 1]

IndexError: too many indices for array

我如何在不创建新数组的情况下进行索引?

一维数组只有a 单件尺寸仍然是尺寸。

b删除第二维:

a[b[:, 0] > 0]

b[:, 0]查看b的数据,而不是副本。

暂无
暂无

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

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