1

I'm trying to initialize an "empty" array with each elements containing t_list a 8x8 np.zeros array :

t_list = np.zeros((8,8), dtype=np.float32)

I would now want to have a np.array with multiple t_list at each indexes:

result = np.array((t_list, t_list, ...., tlist))

I would like to be able to control the number of time t_list is in result.

I know that I could use list instead of arrays. The problem is, I put this in a numba njit function so I need to precise everything.

The aim is then to change each values in a double for loop.

3
  • 4
    why not give np.zeroes another dimension? like result = np.zeros((5,8,8), dtype=np.float32) Commented Dec 2, 2021 at 13:58
  • 1
    It perfectly works! Thanks a lot Commented Dec 2, 2021 at 14:03
  • Cool! making it a proper answer then :) Commented Dec 4, 2021 at 6:55

1 Answer 1

1

The shape param of numpy.zeros can be a tuple of ints of any length, so you can create an ndarray with multiple dimensions.

e.g.:

n = 5 # or any other number that you want
result = np.zeros((n,8,8), dtype=np.float32)
Sign up to request clarification or add additional context in comments.

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.