Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 meta array question
#1
I'm modelling a 3D space.

I'd like to create a large multi dim array , like numpy.empty((720,720,720),dtype=object) in size, but anticipate for most of the program run time, few of the array elements will be used. The array indices are more for reference.

Is just using numpy.empty a decent way to do this? I'm not sure that initially creating 720x720x720 references to None objects is efficient.

Is a way a better way to dynamically create multii dim array?
Quote
#2
Do you really need to save the memory? That's a pretty big chunk, but if running this is all the machine will be doing anyway it probably wouldn't make much of a difference, especially if you have to write more code.

If you really want to save memory, are you considering not allocating the cubic space at all, and only using values you write to? Are you asking how to do that?
Feel like you're not getting the answers you want? Checkout the help/rules for things like what to include/not include in a post, how to use code tags, how to ask smart questions, and more.

Pro-tip - there's an inverse correlation between the number of lines of code posted and my enthusiasm for helping with a question :)
Quote
#3
>Are you asking how to do that?

Yes. The idea is to list objects in each cubical.
But at the start the space will be sparely populated. I thought maybe a dictionary would be better i.e.

cubic = {}
cubic['231 098 045' ] =[ship,planet,moon,rock,star]
No need to set all the other cubicals as None
I'd need a bit more code to convert the dictionary entry names into integers triples though.
Quote
#4
At first I was thinking of a nested dictionary structure, but then I realized that you can actually just use tuples as dictionary keys.

Do you need to do anything with ranges? Or are you always just checking specific "cubicles"? Tuple keys would be great in the latter case but in the former case things get potentially more complicated.
Feel like you're not getting the answers you want? Checkout the help/rules for things like what to include/not include in a post, how to use code tags, how to ask smart questions, and more.

Pro-tip - there's an inverse correlation between the number of lines of code posted and my enthusiasm for helping with a question :)
Quote
#5
awesome. In my training, it never came up that dictionary keys could be integers or tuples. We only used strings as dictionary keys.
Quote
#6
Wow! Yeah, the keys can be anything immutable, meaning you can't change its value. For example, you can't change a string, tuple or integer in-place, you have to replace the whole variable. Contrast that with a list, which can change. The dictionary would then have issues if the way it organizes things internally relies on the keys not changing, so that's a high-level explanation of why.
Feel like you're not getting the answers you want? Checkout the help/rules for things like what to include/not include in a post, how to use code tags, how to ask smart questions, and more.

Pro-tip - there's an inverse correlation between the number of lines of code posted and my enthusiasm for helping with a question :)
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)