“tableau 3 dimensions numpy” Réponses codées

tableau 3 dimensions numpy

# required libraries
import numpy as npy

array_3d = npy.array(
    [[[1, 1, 1, 1],
    [1, 1, 1, 1],
    [1, 1, 1, 1]],
    
    [[1, 1, 1, 1],
    [1, 1, 1, 1],
    [1, 1, 1, 1]]])

print(array_3d)
print("Number of dimensions: " ,array_3d.ndim, ", Shape: ", array_3d.shape)
# you can type the array yourself like this
# or you could do somethong like this

ones = npy.ones((2, 3, 4), dtype=int)
print(ones)
print("Number of dimensions: " ,ones.ndim, ", Shape: ", ones.shape)
# and get the same result
ST111

Indexation multidimensionnelle numpy

# Let's say you have a batch of 256 inputs, each one has a set of 64 points.
x.shape --> (256, 64, 3)

# Now assume you want to index each image and draw 128 samples of those points,
# with an indices matrix.
idx.shape --> (256, 128)

# Do
y = x[np.arange(x.shape[0]), idx.T].reshape((1, 0, 2))
y.shape --> (256, 128, 3)

Testy Toad

Réponses similaires à “tableau 3 dimensions numpy”

Questions similaires à “tableau 3 dimensions numpy”

Plus de réponses similaires à “tableau 3 dimensions numpy” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code