[英]Numpy - Array how to reshape it
我在数组中存储了类 [0,1] 是负类,[1,0] 是正值类,现在我想重塑它。
我的输入数组是这样的
[[0, 1], [1, 0], [0, 1], [1, 0], [0, 1], [1, 0], [0, 1], [1, 0], [0, 1], [1, 0], [0, 1], [1, 0], [0, 1], [1, 0], [0, 1], [1, 0], [0, 1], [1, 0], [0, 1], [1, 0], [0, 1], [1, 0], [0, 1], [1, 0]]
我正在尝试像这样重塑它
ponlabel=np.array(ponlabel)
PositiveorNegativeLabel = ponlabel.reshape(24, 1)
print(PositiveorNegativeLabel)
获取错误无法将大小 48 重塑为 (24,1)
如果您仅尝试提取第一个值,请使用:
ponlabel[:, 0]
#array([1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0])
这同样适用于第二个值:
ponlabel[:, 1]
#array([0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1])
我不太清楚你需要什么,你能更具体一点吗? 也许是这样的:
a=[[0, 1], [1, 0], [0, 1], [1, 0], [0, 1], [1, 0], [0, 1], [1, 0], [0, 1], [1, 0], [0, 1], [1, 0], [0, 1], [1, 0], [0, 1], [1, 0], [0, 1], [1, 0], [0, 1], [1, 0], [0, 1], [1, 0], [0, 1], [1, 0]]
b=[]
for i in range(len(a)):
for i in range(len(a)):
if a[i]==[0,1]:
b.append(False)
else:
b.append(True)
与 b 喜欢:
[False, True, False, True, False, True, False, True, False, True, False, True, False, True, False, True, False, True, False, True, False, True, False, True]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.