Programming/python

How to reshape numpy array (ndarray) - 넘파이 어레이 크기 변경하는 방법 2가지

방황하는 데이터불도저 2023. 1. 2. 19:55

# 1

numpy.reshape(a, newshape, order='C')

 

Parameters

a : array_like  (재변형할 array 변수를 넣어주기)

newshpae : int or tuple of ints  (재변형시킬 shape 크기를 정수형 또는 튜플형으로 입력)

order : {‘C’, ‘F’, ‘A’}, optional

  ('C' : 가장 마지막 index의 축이 가장 먼저 변화함) - C언어 방식 

  ('F' : 가장 첫 index의 축이 가장 먼저 변화함) - Fortran언어 방식

  ('A' : a의 정렬에 따라 자동으로 C또는 F로 읽거나/씀) - Auto

 

Returns

reshaped_array : ndarray  (새로운 객체로 선언)

 

 

# 2

ndarray.reshape(shape, order='C')

a.reshape(10, 11)
# is same with
a.reshape((10,11))

#1과 파라미터는 동일하지만 리턴값이 새로운 객체로 선언되는 것이 아닌 a (Array)에 바로 적용되는 방식의 함수