2013-07-24 15 views

cevap

23

Böyle kolay:

k.reshape(k.shape + (1,)) 

Ama istediğin sonunda boş bir boyut eklemek için ise, kullanmalısınız

numpy.newaxis:

import numpy as np 
k = k[..., np.newaxis] 

veya

k = k[..., None] 

(Bkz. documentation on slicing).

0

python3.5 itibaren, np.ndarray.shapenp.reshape içeride ile açma kullanabilirsiniz:

>>> my_array = np.array([1,2,3,4]) 
>>> my_array.reshape(1, *my_array.shape) 
array([[1, 2, 3, 4]]) 
>>> my_array.reshape(*my_array.shape, 1) 
array([[1], 
     [2], 
     [3], 
     [4]]) 

my_array.reshape(1, *my_array.shape) eser eski sürümlerinde de.

İlgili konular