[英]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.