“Rumpy Reshape (n) à (n 1)” Réponses codées

convertir la forme np (a,) en (a, 1)

# numpy array/vector (n,) dimension -> (n,1) dimension conversion
a  = np.arange(3)         # a.shape  = (3,)
b  = a.reshape((3,1))     # b.shape  = (3,1)
c  = b.reshape((3,))      # c.shape  = (3,)

c2 = b.reshape((-1,1))    # c2.shape = (3,)
Brave Bee

Reshape (n) à (n 1)

'''
This code is contributed by :
Tanishq Vyas (github : https://github.com/tanishqvyas )
'''

actual = actual.reshape((actual.shape[0], 1))
Tanishq Vyas

Rumpy Reshape (n) à (n 1)

""" assuming that v is a numpy array with shape (N, ) """
new_v = v.reshape(-1, 1) # new_v.shape is (N, 1)
wolf-like_hunter

remodeler

>>> a = np.array([[1,2,3], [4,5,6]])
>>> np.reshape(a, 6)
array([1, 2, 3, 4, 5, 6])
>>> np.reshape(a, 6, order='F')
array([1, 4, 2, 5, 3, 6])
>>> np.reshape(a, (3,-1))       # the unspecified value is inferred to be 2
array([[1, 2],
       [3, 4],
       [5, 6]])
Dull Dogfish

Réponses similaires à “Rumpy Reshape (n) à (n 1)”

Questions similaires à “Rumpy Reshape (n) à (n 1)”

Plus de réponses similaires à “Rumpy Reshape (n) à (n 1)” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code