2017-09-06 69 views
0

什麼是在python中索引1d數組變量的過程?如何索引1d數組沒有單身維度在Python中由1d數組與單身維數?

例如,請考慮下面的例子:

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 

我怎麼會做這樣的索引,而無需創建一個新的數組?

回答

0

只有a是一維數組。單例尺寸仍然是尺寸。

b從刪除第二尺寸:

a[b[:, 0] > 0] 

b[:, 0]b需要的數據的視圖,而不是拷貝。

相關問題