I have 2 vectors, posVec and dirVec who's value I woudl like to keep at (0.0,0.0,0.0).
So I set up temporary vectors t_pos & t_dir and change their values depending on the value of cylCut
Then on the next iteration of the loop I reset the temporary vectors.
The code:
import numpy as np
posVec = np.array([0.0,0.0,0.0]) # orginal vectors
dirVec = np.array([0.0,0.0,0.0])
print "................."
print 'Before'
print "................."
print posVec
print dirVec
print "................."
for cylCut in range(0,3):
t_pos = posVec # temporary vectors
t_dir = dirVec
if cylCut == 0: # set temp vects accordingly
print '0'
t_pos[0] = 1.0
t_dir[0] = 1.0
if cylCut == 1:
print '1'
t_pos[1] = 1.0
t_dir[1] = 1.0
if cylCut == 2:
print '2'
t_pos[2] = 1.0
t_dir[2] = 1.0
print t_pos
print t_dir
print "................."
print 'After'
print "................."
print posVec
print dirVec
print "................."
For an unknown reason (to me at least) the contents of posVec & posDir are also being changed.
The output I'm getting,
.................
Before
.................
[ 0. 0. 0.]
[ 0. 0. 0.]
.................
0
[ 1. 0. 0.]
[ 1. 0. 0.]
1
[ 1. 1. 0.]
[ 1. 1. 0.]
2
[ 1. 1. 1.]
[ 1. 1. 1.]
.................
After
.................
[ 1. 1. 1.]
[ 1. 1. 1.]
.................
Why is this happening? At not point am I explicitly changing the vectors. Does Python/Numpy automatically link variable? Why would you do that? How do I stop it?