2

Can I use numpy to create an array that can hold up to 12 objects?? I have an object like app.feOutput and I need 12 variables initialized with that object.

I hope someone can help me. Just new to python stuff especially handling objects.

5
  • Do you mean you want to initialize an empty array and assign objects later? looking for np.empty((12,), dtype=object) maybe? Commented Jun 16, 2020 at 9:39
  • Object dtype arrays are a bit advanced for Python beginners. Why aren't you using a list? Commented Jun 16, 2020 at 10:47
  • Assigning one object to all 12 slots of an object dtype array will have the same problem as making a list with 12 references to that object. Commented Jun 16, 2020 at 15:50
  • 1
    @Ehsan Thank you for the info. Still new to the StackOverflow community. Commented Jun 17, 2020 at 3:32
  • @hpaulj it was referred to me by my friend to use it for handling larger quantity of data but I'll take note on what you mention. Thank you very much Commented Jun 17, 2020 at 3:36

1 Answer 1

3

You can initialize an empty array like this:

a = np.empty((12,), dtype=object)

And later you can assign your desired objects to its element:

a[i] = obj_i
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.