LoginSignup
0
0

More than 5 years have passed since last update.

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

Posted at

@ 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に入る。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0