# 我有一个单列数据。我想重塑它，以便我可以将其用于 RNN

2023-01-04 16:40:03

`X_train=np.reshape(Y,(Y.shape[0],Y.shape[1],1))`

IndexError：元组索引超出数据集范围

## 2 回答

catspeake

TA贡献848条经验 获得超0个赞

import numpy as np

Y = np.random.rand(3, 4)

print(Y)

Y = np.reshape(Y, (Y.shape[0], Y.shape[1], 1))

print(Y)

[[0.94716449 0.46469876 0.74290887 0.11051443]

[0.31187829 0.26831897 0.37580931 0.23038081]

[0.46578756 0.81175453 0.98348175 0.02975313]]

[[[0.94716449]

[0.46469876]

[0.74290887]

[0.11051443]]

[[0.31187829]

[0.26831897]

[0.37580931]

[0.23038081]]

[[0.46578756]

[0.81175453]

[0.98348175]

[0.02975313]]]

TA贡献1560条经验 获得超5个赞

Y = np.random.rand(3, 4)

Y.reshape((Y.shape[0], Y.shape[1], 1))

array([[[0.03398233],

[0.31845358],

[0.26508794],

[0.4154345 ]],

[[0.80924495],

[0.86116906],

[0.24186532],

[0.64169452]],

[[0.61352962],

[0.95214732],

[0.26994666],

[0.99091755]]])

Y.reshape((1, 1, -1))

array([[[0.52130672]],

[[0.25807463]],

[[0.81201524]],

[[0.08846268]],

[[0.20831986]],

[[0.823997  ]],

[[0.483052  ]],

[[0.15120415]],

[[0.19601734]],

[[0.55933897]],

[[0.9112403 ]],

[[0.1048653 ]]])

• 2 回答
• 0 关注
• 17 浏览

0/150