[英]How to change a specific numpy array inside a arrays of arrays?
I'm writing a program but I'm finding dificulties to update a numpy array.我正在编写一个程序,但我发现更新 numpy 数组有困难。 The code:
代码:
print("p: " + str(pontoP))
print("d: " + str(deslocamento))
novoP = np.array([0,0,0])
novoP = pontoP + deslocamento
pontos[i] = novoP
print("p+d: " + str(pontos[i]))
The output: output:
p: [0. 1. 0.33333333]
d: [ 0. -1. 0.]
p+d: [0 0 0]
pontoP , novoP and deslocamento are 1D numpy arrays (length 3), and pontos is a 2D numpy array (size 8 x 3). pontoP 、 novoP和deslocamento是 1D numpy arrays(长度 3),而pontos是 2D numpy 数组(大小 8 x 3)。
The line novoP = pontoP + deslocamento is working: the arrays are being summed element-wise.行novoP = pontoP + deslocamento正在运行:arrays 正在按元素求和。 However, pontos[i] = novoP is failing to update the 2D array pontos .
但是, pontos[i] = novoP无法更新二维数组pontos 。 What can I do?
我能做些什么? The desired result is to replace the ith array of pontos with the contents of novoP .
期望的结果是用novoP的内容替换第 i 个pontos数组。
Thanks to @hpauli, I found that the issue was the type of numpy array.感谢@hpauli,我发现问题出在 numpy 数组的类型上。 It was an
int
and when I tried to put a float in it, the float was being rounded.它是一个
int
,当我试图在其中放入一个浮点数时,该浮点数被舍入了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.