import numpy as np
a1 = np.arange(30).reshape(5,6)
print(a1)
# result
# [[ 0 1 2 3 4 5]
[ 6 7 8 9 10 11]
[12 13 14 15 16 17]
[18 19 20 21 22 23]
[24 25 26 27 28 29]]
np.add.reduce(a1, axis=1)
# result : [ 15 51 87 123 159]
np.add.reduce(a1, axis=1, where = a1%2==0)
# result : [ 6 24 42 60 78]
print(np.add.reduce(a1, axis = (0,1)))
# result : 435
np.add.accumulate(a1,axis=1)
# result
# [[ 0 1 3 6 10 15]
[ 6 13 21 30 40 51]
[ 12 25 39 54 70 87]
[ 18 37 57 78 100 123]
[ 24 49 75 102 130 159]]
์ ๋ชจ๋ฅด๊ฒ ๋ค.
a2 = np.arange(10)
a3 = np.arange(100,105)
print(a2, a2.shape)
print(a3, a3.shape)
# result
# [0 1 2 3 4 5 6 7 8 9] (10,) -> a2
[100 101 102 103 104] (5,) -> a3
a4 = np.add.outer(a2,a3)
print(a4,a4.shape)
# result
# [[100 101 102 103 104]
[101 102 103 104 105]
[102 103 104 105 106]
[103 104 105 106 107]
[104 105 106 107 108]
[105 106 107 108 109]
[106 107 108 109 110]
[107 108 109 110 111]
[108 109 110 111 112]
[109 110 111 112 113]] (10, 5)