目录
1.报错:ValueError: shapes (2,) and (4,) not aligned
ValueError: shapes (2,) and (4,) not aligned: 2 (dim 0) != 4 (dim 0)
解决:这种情况一般是由于数据类型为ndarry
利用reshape()解决,如
b = b.reshape(2,1)
c = c.reshape(4,1)
即可操作。
2.目的:list写入txt, list元素之间为空格,结尾处为回车格式
假如有循环不断求得list_test,需不断list_test写入txt
list_test=[1,2,3,4,5]
list_test=[2,3,4,5,6]
即目标txt为
1 2 3 4 5\n
2 3 4 5 6\n
则代码为
for …… in ……
list_test = ……
with open(drty+'list_test.txt', 'at') as output:
output.write(str(list_test[0]))
for line in w[1:]:
output.write(" "+str(line))
output.write('\n')
3.plotly坐标轴3d特别奇怪,原因可能在于列元素类型为object
plotly 3d scatter 找了好久的错误,坐标轴竟然还可以从小到大到小,原来是数据类型不是float类型
df['x'] = df['x'].astype(float)
df['y'] = df['y'].astype(float)
df['z'] = df['z'].astype(float)
改完就好啦,‘x’是列名。