import numpy as np
lista = [[10,20,30],[40,50,60]]
a = np.array(lista)
print(a)
# [[10 20 30]
[40 50 60]]
.
.
a1 = a.flatten()
print(a1) # [10 20 30 40 50 60]
a1[2] = 100
print(a1) # [10 20 100 40 50 60]
print(a)
# [[10 20 30]
[40 50 60]]
a2 = a.ravel() # [10 20 30 40 50 60]
print(a2)
a2[2] = 100
print(a2) # [10 20 100 40 50 60]
print(a)
# [[ 10 20 100]
[ 40 50 60]]
.
.
a1 = np.arange(10,20).reshape(2,5)
a2 = np.arange(110,120).reshape(2,5)
print(a1)
# [[10 11 12 13 14]
[15 16 17 18 19]]
print(a2)
# [[110 111 112 113 114]
[115 116 117 118 119]]
print(np.concatenate((a1,a2),axis=0))
# [[ 10 11 12 13 14]
[ 15 16 17 18 19]
[110 111 112 113 114]
[115 116 117 118 119]]
print(np.concatenate((a1,a2),axis=1))
# [[ 10 11 12 13 14 110 111 112 113 114]
[ 15 16 17 18 19 115 116 117 118 119]]
print(np.hstack((a1,a2)))
# [[10 11 12 13 14 110 111 112 113 114]
[15 16 17 18 19 115 116 117 118 119]]
print(np.vstack((a1,a2)))
[[ 10 11 12 13 14]
[ 15 16 17 18 19]
[110 111 112 113 114]
[115 116 117 118 119]]
b = np.concatenate((a1,a1),axis=1)
print(b)
# [[ 10 11 12 13 14 110 111 112 113 114]
[ 15 16 17 18 19 115 116 117 118 119]]
print(np.hsplit(b,5))
# [array([[10, 11],
[15, 16]]), array([[12, 13],
[17, 18]]), array([[ 14, 110],
[ 19, 115]]), array([[111, 112],
[116, 117]]), array([[113, 114],
[118, 119]])]
b2 = b.T
print(b2)
# [[ 10 15]
[ 11 16]
[ 12 17]
[ 13 18]
[ 14 19]
[110 115]
[111 116]
[112 117]
[113 118]
[114 119]]
print(np.vsplit(b2,5))
# [array([[10, 15],
[11, 16]]), array([[12, 17],
[13, 18]]), array([[ 14, 19],
[110, 115]]), array([[111, 116],
[112, 117]]), array([[113, 118],
[114, 119]])]
: np.sum(array, axis, keepdims)
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]]
» axis = 1 을 따라 sum
np.sum(a1, axis = 1)
# result
# array([ 15, 51, 87, 123, 159])
» axis = 0 을 따라 sum
np.sum(a1, axis=0)
# result
# array([60, 65, 70, 75, 80, 85])