我有一個二維 (2D) 陣列,其中包含許多隨機布林值的一維 (1D) 陣列。
import numpy as np
def random_array_of_bools():
return np.random.choice(a=[False, True], size=5)
boolean_arrays = np.array([
random_array_of_bools(),
random_array_of_bools(),
... so on
])
假設我有三個陣列:
[True, False, True, True, False]
[False, True, True, True, True]
[True, True, True, False, False]
這是我想要的結果:
[False, False, True, False, False]
如何使用 NumPy 實作這一目標?
uj5u.com熱心網友回復:
使用min有axis=0:
>>> boolean_array.min(axis=0)
array([False, False, True, False, False])
>>>
uj5u.com熱心網友回復:
嘗試 numpy bitwise_and =>
out_arr = np.bitwise_and(np.bitwise_and(in_arr1, in_arr2),in_arr3)
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/326705.html
上一篇:Next.js Typescript mongoose使用`letcached=global.mongoose`時出錯
下一篇:更改2dnumpy陣列的結構
