일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 준비
- List Comprehension
- K 데이터 자격시험
- 빅데이터 분석기사
- context manger1
- 시험 일정
- pythonML
- Seaborn
- 응시료
- matplotlib
- teen learn
- 검정수수료
- numpy
- separating data(데이터 분리하기)
Archives
- Today
- Total
재원's 블로그
넘파이 기본함수와 사용법 본문
최초 작성일 : 2021-11-05
categories: Numpy
-넘파이 불러오기
import numpy as np
print(np.__version__)
1.19.5
-넘파이 기본함수 zeros()
zeros_array = np.zeros((3,2))
print(zeros_array)
print("Data Type is:", zeros_array.dtype)
print("Data Shape is:", zeros_array.shape)
[[0. 0.]
[0. 0.]
[0. 0.]]
Data Type is: float64
Data Shape is: (3, 2)
-넘파이 기본함수 ones()
ones_array = np.ones((3,4), dtype='int32')
print(ones_array)
print("Data Type is:", ones_array.dtype)
print("Data Shape is:", ones_array.shape)
[[1 1 1 1]
[1 1 1 1]
[1 1 1 1]]
Data Type is: int32
Data Shape is: (3, 4)
-넘파이 기본함수 reshape()
# 3 X 4 배열을 Reshape --> 6 x 2
after_reshape = ones_array.reshape(6,2)
print(after_reshape)
print("Data Shape is:", after_reshape.shape)
[[1 1]
[1 1]
[1 1]
[1 1]
[1 1]
[1 1]]
Data Shape is: (6, 2)
after_reshape = ones_array.reshape(3,4)
# 3 x 4 12 --> 2 x 3 x 2 = 12
after_reshape = ones_array.reshape(2,3,2)
print(after_reshape)
print("Data Shape is:", after_reshape.shape)
[[[1 1]
[1 1]
[1 1]]
[[1 1]
[1 1]
[1 1]]]
Data Shape is: (2, 3, 2)
after_reshape2= ones_array.reshape(2, -1, 2)
print("reshape(-1,2)?", after_reshape2.shape)
print(after_reshape2)
reshape(-1,2)? (2, 3, 2)
[[[1 1]
[1 1]
[1 1]]
[[1 1]
[1 1]
[1 1]]]
after_reshape3= ones_array.reshape(3,-1)
print("reshape(3, -1)? \n")
print(after_reshape3)
print("Data Shape is:", after_reshape3.shape)
reshape(3, -1)?
[[1 1 1 1]
[1 1 1 1]
[1 1 1 1]]
Data Shape is: (3, 4)