I'm writing a program but I'm finding dificulties to update a numpy array. 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:
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).
The line novoP = pontoP + deslocamento is working: the arrays are being summed element-wise. However, pontos[i] = novoP is failing to update the 2D array pontos . What can I do? The desired result is to replace the ith array of pontos with the contents of novoP .
Thanks to @hpauli, I found that the issue was the type of numpy array. It was an int
and when I tried to put a float in it, the float was being rounded.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.