What are the row and column directions? I will leave a note before I forget it.
axis=0 Line direction = 1st line to mth line
axis=1 Column direction = 1st column to nth column
It will be simple if you catch it
a = np.array([
[1, 1, 1],
[1, 0, 1],
[1, 0, 0],
])
print(np.all(a, axis=0)) #Row direction(From line 1 to line m)To see
print(np.all(a, axis=1)) #Column direction(From the 1st column to the nth column)
)To see
print(a)
a[2,0] = 0
print(np.all(a, axis=0))
print(np.all(a, axis=1))
>>> [ True False False]
>>> [ True False False]
>>>
[[1 1 1]
[1 0 1]
[1 0 0]]
>>> [False False False] #From line 1 to line m
Look at True,False has been decided
>>> [ True False False] #From the 1st column to the nth column
Look at True,False has been decided
a = np.array([[1,2,3],
[4,5,6]])
print(a)
np.sum(a, axis=0)
np.sum(a, axis=1)
>>> [[1 2 3]
[4 5 6]]
>>> array([5, 7, 9]) #It is added along the 1st line to the mth line
>>> array([ 6, 15]) #It is added along the 1st to nth columns
Recommended Posts