Python lists are pointers so I can do the following:
a = []
b = a
b.append(1)
>>> print a, b
[1] [1]
What is the way to accomplish this behavior using numpy? Because numpy's append creates a new array. That is:
a = np.array([])
b = a
b = np.append(b, 1)
>>> print a, b
[] [1.]
EDIT What I'm trying to accomplish:
I have a large text file which I'm trying to parse with re
: Depending on a marker in the file, I want to change the array I'm appending to. For example:
x = np.array([])
y = np.array([])
with open("./data.txt", "r") as f:
for line in f:
if re.match('x values', line):
print "reading x values"
array = x
elif re.match('y', line):
print "reading y values"
array = y
else:
values = re.match("^\s+((?:[0-9.E+-]+\s*)*)", line)
if values:
np.append(array, values.groups()[0].split())