# Similar manipulations on several numpy arrays

I have n numpy arrays which all contain time series data for t periods. It is not an option to instead have one nxt matrix. I am storing all these arrays in a ResultSimulation object.

I seem to have repetitive code, which I am wondering how to shorten.

It starts with

ResultSimulation.v0 = ResultSteadyState.v0[::-1].copy()


at some place there is

# nTSteady is some number


and finally,

addZeros = np.zeros((additionalSize,))


I guess one way to reduce this repetitive code, is to use "variable variable names", a practice that isn't encouraged in Python. Another alternative is to store them not directly in the object, but in an intermediate dict:

for series in ResultSimulation.myDict:


for the first case. Say I don't like these two options+. What else can I do?

+: I dont mind creating an intermediate dictionary, but I want to keep my numpy arrays as properties of the object, and not stored in a dictionary within the object.

You can get the behavior you want using getattr and setattr, this should do the trick for your first example:
for attr in ('v0', 'v1', 'nl', 'nh', 'ul', 'uh', 'V1'):