“Numpy Reshape (n) zu (n 1)” Code-Antworten

Konvertieren Sie die NP -Form (a,) in (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

Umformung (n) zu (n 1)

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

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

Numpy Reshape (n) zu (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

Numpy -Umgestaltung

>>> 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

Ähnliche Antworten wie “Numpy Reshape (n) zu (n 1)”

Fragen ähnlich wie “Numpy Reshape (n) zu (n 1)”

Weitere verwandte Antworten zu “Numpy Reshape (n) zu (n 1)” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen