Numpy > array comparisons > np.all()の使用


@ Scipy lecture notes, Edition 2017.1
https://www.scipy-lectures.org/_downloads/ScipyLectures-simple.pdf
3.2.2 Basic reductions
Other reduction
p63
https://www.scipy-lectures.org/intro/numpy/operations.html#other-reductions

Note Can be used for array comparisons:

np.all()とnp.any()を使ったarray comparisonが可能とのこと。

import numpy as np

a = np.array([1, 2, 3, 2])
b = np.array([2, 2, 3, 2])
c = np.array([6, 4, 4, 5])
res = ((a <= b) & (b <= c)).all()
print(res)

run
True

比較した結果がリストでTrueかFalseの要素を持ち、それがすべてTrueの時にresがTrueになるという流れ。

.all()がない場合は、[True True True True]がresに入る。