Why do these np arrays not add up?

I’m writing my version of particle life in python and I run into a problem I don’t understand.

I have 2 np arrays with the same type and size and they don’t add up.

after the adding the array " v[pairs[:,0]] [within_repulsion_range] " stays the same. How come?
Thanks a lot for your help.
Here is the code and it’s output.

print("_before adding_")
print("v[pairs[:,0]] [within_repulsion_range] ")
print( v[pairs[:,0]] [within_repulsion_range])
print("np.shape([pairs[:,0]] [within_repulsion_range])")
print( np.shape(v[pairs[:,0]] [within_repulsion_range]))
print("type(v[pairs[:,0]] [within_repulsion_range])")
print( type(v[pairs[:,0]] [within_repulsion_range]))
print() 
print()
print("fa")
print( fa)
print("np.shape(fa)")
print( np.shape(fa))
print("type(fa)")
print( type(fa))
print()

v[pairs[:,0]] [within_repulsion_range] += fa

print("  _ after adding _ ")
print("v[pairs[:,0]] [within_repulsion_range]")
print( v[pairs[:,0]] [within_repulsion_range])
print()

This is the output :

before adding
v[pairs[:,0]] [within_repulsion_range]
[[0. 0.]
[0. 0.]
[0. 0.]
[0. 0.]]
np.shape([pairs[:,0]] [within_repulsion_range])
(4, 2)
type(v[pairs[:,0]] [within_repulsion_range])
<class ‘numpy.ndarray’>

fa
[[ 0.06967497 -0.22706683]
[-0.01281208 -0.41799156]
[-0.68587809 -0.34792648]
[-0.6120704 0.37358037]]
np.shape(fa)
(4, 2)
type(fa)
<class ‘numpy.ndarray’>

_ after adding _
v[pairs[:,0]] [within_repulsion_range]
[[0. 0.]
[0. 0.]
[0. 0.]
[0. 0.]]

Just to clarify your problem, when you say they don’t add up, do you mean:

  1. You get some sort of error when you attempt to add them together
    or
  2. You can successfully add them together but the result is not what you expected
1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.