Numpy. section4 : ndarray 바꾸기. Lec12. np.reshape에서의 -1

timekeeep·2023년 2월 23일
0

Numpy

목록 보기
11/28

[1] -1 in np.reshape

  • row 나 column의 개수를 강조할때 사용가능함
import numpy as np

a = np.arange(12)

b = a.reshape((2,-1)) # 처음 것을 fix하면 뒤는 자동적으로 결정됨
c = a.reshape((3,-1))
d = a.reshape((4,-1))
e = a.reshape((6,-1))

print(b.shape, c.shape, d.shape, e.shape)

b = a.reshape((-1,2))
c = a.reshape((-1,3))
d = a.reshape((-1,4))
e = a.reshape((-1,6))

print(b.shape, c.shape, d.shape, e.shape)

a = np.arange(24)

b = a.reshape((2,3,-1))
c = a.reshape((2,-1,4))
d = a.reshape((-1,3,4))

a = np.random.randint(0, 10, size = (2,2))

print(a)

row_vector = a.reshape(1,-1)
col_vector = a.reshape(-1, 1)

print(row_vector.shape, col_vector.shape)

profile
Those who are wise will shine like the brightness of the heavens, and those who lead many to righteousness, like the stars for ever and ever

0개의 댓글