在:-1

问题描述 投票:0回答:0

在下面的代码中,我想在使用后检查每个数组的形状:-1 和 -1。我认为那将是 x.shape= [2,4,3] ,y.shape =[2,1,3] 。但输出是 x.shape= [2,4,3], y.shape=[2,3]。我很困惑 y 的第二维在哪里?

如果有朋友能帮我解决的话,非常感谢。

#code--
import numpy as np
a = np.random.rand(2,5,3)
print(a)
x = a[:,:-1,:]
y = a[:,-1,:]
print(x.shape)
print(y.shape)

#output
[[[0.18648295 0.45018899 0.37269369]
  [0.28727699 0.74595982 0.24410613]
  [0.73484484 0.62852367 0.71091093]
  [0.82692484 0.93791066 0.31497567]
  [0.5506998  0.3992407  0.55229818]]

 [[0.33900664 0.37279058 0.59162413]
  [0.18841992 0.94866945 0.7417921 ]
  [0.67865254 0.61119384 0.49094303]
  [0.07091689 0.55436234 0.80671508]
  [0.37598695 0.96572699 0.04268124]]]
(2, 4, 3)
(2, 3)

我希望有人能回答我的问题。

your text

arrays numpy artificial-intelligence shapes
© www.soinside.com 2019 - 2024. All rights reserved.