假設我有一個大小為 10 的陣列:
x = np.linspace(0.1, 1, 10)
我在這些 x 上有一個函式值陣列:
fx = np.sin(x)
現在我有一個子陣列x,例如,
sub_x = x[::2]
如何提取fx中子點的值sub_x?IE,
fx[indices of x that are in sub_x]
這不起作用:fx[x == sub_x].
uj5u.com熱心網友回復:
這應該這樣做:
fx[np.in1d(x, sub_x)]
uj5u.com熱心網友回復:
你可以這樣做np.isin:
fx[np.isin(x, sub_x)]
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/454650.html
標籤:Python 麻木的 索引 numpy-ndarray
