“Numpy -Umgestaltung” Code-Antworten

np.reshape ()

a = np.arange(6).reshape((3, 2))
>>> a
array([[0, 1],
       [2, 3],
       [4, 5]])
Careful Caterpillar

neu Array Numpy umformen

a = np.arange(6)
np.reshape(a, newshape=(1, 6))
BlueMoon

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

np.reshape ()

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])
Vast Vendace

Beispiel für Python Numpy Reshape -Funktion

# Welcome to softhunt.net
# Python Program illustrating
# numpy.reshape() method
 
import numpy as np
 
# array = np.arrange(8)
# The 'numpy' module has no attribute 'arrange'
array1 = np.arange(8)
print("Original array : \n", array1)
 
# shape array with 3 rows and 3 columns
array2 = np.arange(8).reshape(2, 4)
print("\narray reshaped with 2 rows and 4 columns : \n",
      array2)
 
# shape array with 4 rows and 2 columns
array3 = np.arange(8).reshape(4, 2)
print("\narray reshaped with 4 rows and 2 columns : \n",
      array3)
 
# Constructs 3D array
array4 = np.arange(8).reshape(2, 2, 2)
print("\nOriginal array reshaped to 3D : \n",
      array4)
Outrageous Ostrich

Ähnliche Antworten wie “Numpy -Umgestaltung”

Fragen ähnlich wie “Numpy -Umgestaltung”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen