How to understand "reshape(-1)"

2019-02-09  本文已影响0人  宣雄民
In [1]: import numpy as np                                                                                             

In [2]: orig_list = np.array([[1,2,3,4], [22,33,11,11], ['a', 'b', 'c', 'd']])                                         

In [3]: orig_list                                                                                                      
Out[3]: 
array([['1', '2', '3', '4'],
       ['22', '33', '11', '11'],
       ['a', 'b', 'c', 'd']], dtype='<U21')

In [4]: orig_list.shape                                                                                                
Out[4]: (3, 4)

In [5]: new_list = orig_list.reshape(-1)                                                                               

In [6]: new_list                                                                                                       
Out[6]: 
array(['1', '2', '3', '4', '22', '33', '11', '11', 'a', 'b', 'c', 'd'],
      dtype='<U21')

In [7]: new_list.shape                                                                                                 
Out[7]: (12,)

In [8]:  

上一篇下一篇

猜你喜欢

热点阅读