Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reshaping data in numpy with (-1,1). What does it mean?

I get from https://stackoverflow.com/a/57417883/6861378 what np.reshape(-1) does. It's reshaping it into 1D array. But what about (a,(-1,1))?

a_concat = np.reshape(a,(-1,1))
like image 873
rulisastra Avatar asked Nov 01 '25 04:11

rulisastra


1 Answers

reshape(-1) is a line vector, when reshape(-1,1) is a column:

>>> import numpy as np
>>> a = np.linspace(1,6,6).reshape(2,3)
>>> a
array([[ 1.,  2.,  3.],
       [ 4.,  5.,  6.]])
>>> a.shape
(2, 3)
>>> a.reshape(-1)
array([ 1.,  2.,  3.,  4.,  5.,  6.])
>>> a.reshape(-1,1)
array([[ 1.],
       [ 2.],
       [ 3.],
       [ 4.],
       [ 5.],
       [ 6.]])
like image 65
Demi-Lune Avatar answered Nov 04 '25 00:11

Demi-Lune