“Matriz tridimensional numpy” Respostas de código

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

Indexação multidimensional 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

Respostas semelhantes a “Matriz tridimensional numpy”

Perguntas semelhantes a “Matriz tridimensional numpy”

Mais respostas relacionadas para “Matriz tridimensional numpy” em Python

Procure respostas de código populares por idioma

Procurar outros idiomas de código