728x90
In [2]:
import numpy as np
In [4]:
test_array = np.arange(1, 11)
test_array
Out[4]:
Sum
In [6]:
test_array.sum(dtype=np.float)
Out[6]:
In [9]:
test_array = np.arange(1, 13).reshape(3,4)
test_array.sum()
Out[9]:
In [12]:
print(test_array)
test_array.sum(axis=1) #칼럼끼리 더한다
Out[12]:
In [14]:
test_array.sum(axis=0) #행끼리 더한다
Out[14]:
In [17]:
third_order_tensor = np.array([test_array, test_array, test_array])
third_order_tensor
Out[17]:
In [19]:
third_order_tensor.sum(axis=2) #column
Out[19]:
In [21]:
third_order_tensor.sum(axis=1) #row
Out[21]:
In [23]:
third_order_tensor.sum(axis=0) #level
Out[23]:
In [25]:
test_array = np.arange(1, 13).reshape(3, 4)
test_array
Out[25]:
Mean
In [27]:
test_array.mean(), test_array.mean(axis=0) #평균
Out[27]:
Std
In [29]:
test_array.std(), test_array.std(axis=0) #표준편차
Out[29]:
Exp, Sqrt
In [31]:
np.exp(test_array), np.sqrt(test_array) #지수, 제곱근
Out[31]:
vstack, hstack
In [33]:
a = np.array([1, 2, 3])
b = np.array([2, 3, 4])
np.vstack((a, b)) #vertical 방향으로 합침
Out[33]:
In [37]:
a = np.array([[1], [2], [3]])
b = np.array([[2], [3], [4]])
np.hstack((a,b)) #horizontal 방향으로 합침
Out[37]:
concatenate
In [39]:
a = np.array([1, 2, 3])
b = np.array([2, 3, 4])
np.concatenate((a, b), axis=0) #1차원 array이므로 row끼리 합쳐짐
Out[39]:
In [43]:
a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6]])
np.concatenate((a, b.T), axis=1) #열끼리 합쳐짐
Out[43]:
tolist()
In [44]:
a.tolist()
Out[44]:
728x90
'Numpy' 카테고리의 다른 글
[Numpy] all&any, comparison, where, argmax&argmin (0) | 2021.07.16 |
---|---|
[Numpy] Operation, Dot product, Broadcasting (0) | 2021.07.16 |
[Numpy] Arange, ones, zeros, empty, eye, identity, digonal, random (0) | 2021.07.16 |
[Numpy] Indexing, Slicing (0) | 2021.07.16 |
[Numpy] Reshape (0) | 2021.07.16 |