0

I'm working on a project related urban public space.

With the following function I got an array related to a raster band of an urban environment.

#array generation function
def shade_array (index):
    altitude = df.altitude[index]
    azimut = df.azimut[index]
    shade = es.hillshade(elevation, azimuth = azimut, altitude = altitude)
    return shade

Now I want to iterate the function for a different days an hour from a dataframe. I run the following for-loop:

for i in df.index:
    shade_array(i)

The point is that what I need is to store the info in a list of variables, like:

array_list = [array_01, array_02,..., array_365]

to cross and make some transformations in the values obtained. How can I get to it?

2 Answers 2

1

If you want to store data as a list of variables, just use list method append() that will append the passed object shade_array(i) into the existing list array_list:

array_list = []  
for i in df.index:
    array_list.append(shade_array(i))

or an even more concise approach may be to use list comprehension as in usr2564301's answer.

Sign up to request clarification or add additional context in comments.

Comments

1

Create the list while you are executing that function:

array_list = [shade_array(i) for i in df.index]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.