1

我的问题是:如何从正在使用的瓷砖中获得b ?

a = np.array([[1,2,-6],[-4,5,6],[10,8,-1]])

b = np.array([
          [[1,2,-6],[1,2,-6],[1,2,-6]],
          [[-4,5,6],[-4,5,6],[-4,5,6]],
          [[10,8,-1],[10,8,-1],[10,8,-1]]
         ])

我这样做了,但我想要更好的东西:

b = np.repeat(a, 3, axis=0).reshape(3,3,3)
4

2 回答 2

1

您已经掌握了 tile 的良好语法:b = np.tile(a,3).reshape((3,3,3))

于 2011-12-08T02:15:56.747 回答
1

您可以使用广播:

b = a.reshape((3,1,3)) * np.ones((1,3,1))
于 2011-12-07T20:04:50.093 回答