728x90
In [2]:
import numpy as np
In [4]:
a = np.arange(10)
a
Out[4]:
In [6]:
a > 5
Out[6]:
Any&All
In [8]:
np.any(a>5), np.any(a<0)
Out[8]:
In [10]:
np.all(a>5), np.all(a<10)
Out[10]:
Comparison
In [12]:
test_a = np.array([1, 3, 0], float)
test_b = np.array([5, 2, 1], float)
test_a > test_b
Out[12]:
In [14]:
test_a == test_b
Out[14]:
In [16]:
(test_a > test_b).any()
Out[16]:
In [18]:
a = np.array([1, 3, 0], float)
np.logical_and(a>0, a<3)
Out[18]:
In [20]:
b = np.array([True, False, True], bool)
np.logical_not(b)
Out[20]:
In [22]:
c = np.array([False, True, False], bool)
np.logical_or(b, c)
Out[22]:
In [24]:
a
Out[24]:
Where
In [25]:
np.where(a > 0, 3, 2) #조건식, True, False
Out[25]:
In [27]:
np.where(a>0) #index 값을 반환
Out[27]:
In [29]:
a = np.arange(5, 15)
a
Out[29]:
In [31]:
np.where(a>10)
Out[31]:
isnan&isfinite
In [33]:
a = np.array([1, np.NaN, np.Inf], float)
np.isnan(a)
Out[33]:
In [35]:
np.isfinite(a)
Out[35]:
argmax&argmin
In [37]:
a = np.array([1,2,4,5,8,78,23,3])
np.argmax(a), np.argmin(a)
Out[37]:
In [38]:
a = np.array([[1,2,4,7], [9,88,6,45],[9,76,3,4]])
np.argmax(a, axis=1), np.argmin(a, axis=0)
Out[38]:
728x90
'Numpy' 카테고리의 다른 글
[Numpy] Fancy index (0) | 2021.07.16 |
---|---|
[Numpy] Operation, Dot product, Broadcasting (0) | 2021.07.16 |
[Numpy] Operation_function, Concatenate (0) | 2021.07.16 |
[Numpy] Arange, ones, zeros, empty, eye, identity, digonal, random (0) | 2021.07.16 |
[Numpy] Indexing, Slicing (0) | 2021.07.16 |