“array 3 dimensi numpy” Kode Jawaban

array 3 dimensi 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

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

Jawaban yang mirip dengan “array 3 dimensi numpy”

Pertanyaan yang mirip dengan “array 3 dimensi numpy”

Lebih banyak jawaban terkait untuk “array 3 dimensi numpy” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya