[英]Reshaping a list containing an array in Python
我想將列表Ii
重塑為(1,11,2)
,但出現錯誤。 我提出了預期的 output。
import numpy as np
Ii=[np.array([[0, 2],
[2, 4],
[2, 5],
[2, 6],
[3, 1],
[3, 7],
[4, 5],
[4, 6],
[5, 3],
[5, 7],
[6, 5]])]
Y=Ii[0].shape
Ii=Ii[0].reshape(1,Y)
錯誤是
in <module>
Ii=Ii[0].reshape(1,Y)
TypeError: 'tuple' object cannot be interpreted as an integer
預期的 output 是
array([[[0, 2],
[2, 4],
[2, 5],
[2, 6],
[3, 1],
[3, 7],
[4, 5],
[4, 6],
[5, 3],
[5, 7],
[6, 5]]])
嘗試這個:
Ii = Ii[0].reshape(1, Y[0], Y[1])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.