If I was writing C++ I could do the following:
double foo [9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
double* bar = foo;
cout << bar[0] << ", " << bar[1] << ", " << bar[2] << "\n";
bar += 3;
cout << bar[0] << ", " << bar[1] << ", " << bar[2] << "\n";
bar += 3;
cout << bar[0] << ", " << bar[1] << ", " << bar[2] << "\n";
This would print:
0, 1, 2
3, 4, 5
6, 7, 8
I now want to do the same in numpy:
foo = np.arange((9))
bar = foo[:3]
print(bar)
???
print(bar)
???
print(bar)
But I don't know what to put at the ??? The result would hopefully be:
[0 1 2]
[3 4 5]
[6 7 8]
In other words, I'm looking for a way to change where the view bar is pointing at foo, using the existing reference bar.
That is I would like to be able to write the ??? as bar = f(bar), where f is some function defined by the user.
Edit:
This is how I'm doing it currently:
def f(idx=[0]): #mutable default argument
idx[0] += 3
return foo[idx[0]-3:idx[0]]
for key in key_list:
a_dict[key] = f()
b_dict[key] = f()
for view in range(num_views):
a_list.append(f())
b_list.append(f())
It needs to be in a vector because scipy.optimize.least_squares needs all values stored in the same vector.