Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8915801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:04:10+00:00 2026-06-15T05:04:10+00:00

it would contain at most 1000 x 1000 x 1000 elements, which is too

  • 0

it would contain at most 1000 x 1000 x 1000 elements, which is too big for python dictionary.

with dict, around 30 x 1000 x 1000 elements, on my machine it already consumed 2gb of memory and everything got stoned.

any modules that can handle 3-dimension array whose value would be only True/False? I check bitarray http://pypi.python.org/pypi/bitarray, which seems reasonable and coded in C, however it seems more like a bit-stream instead of an array, since it supports only 1 dimension.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:04:15+00:00Added an answer on June 15, 2026 at 5:04 am

    numpy has already been suggested by EnricoGiampieri, and if you can use this, you should.

    Otherwise, there are two choices:

    A jagged array, as suggested by NPE, would be a list of list of bitarrays. This allows you to have jagged bounds—e.g., each row could be a different width, or even independently resizable:

    bits3d = [[bitarray.bitarray(1000) for y in range(1000)] for x in range(1000)]
    myvalue = bits3d[x][y][z]
    

    Alternatively, as suggested by Xymostech, do your own indexing on a 1-D array:

    bits3d = bitarray.bitarray(1000*1000*1000)
    myvalue = bits3d[x + y*1000 + z*1000*1000]
    

    Either way, you’d probably want to wrap this up in a class, so you can do this:

    bits3d = BitArray(1000, 1000, 1000)
    myvalue = bits3d[x, y, z]
    

    That’s as easy as:

    class Jagged3DBitArray(object):
        def __init__(self, xsize, ysize, zsize):
            self.lll = [[bitarray(zsize) for y in range(ysize)] 
                        for x in range(xsize)]
        def __getitem__(self, key):
            x, y, z = key
            return self.lll[x][y][z]
        def __setitem__(self, key, value):
            x, y, z = key
            self.lll[x][y][z] = value
    
    class Fixed3DBitArray(object):
        def __init__(self, xsize, ysize, zsize):
            self.xsize, self.ysize, self.zsize = xsize, ysize, zsize
            self.b = bitarray(xsize * ysize * zsize)
        def __getitem__(self, key):
            x, y, z = key
            return self.b[x + y * self.ysize + z * self.ysize * self.zsize]
        def __setitem__(self, key, value):
            x, y, z = key
            self.b[x + y * self.ysize + z * self.ysize * self.zsize] = value
    

    Of course if you want more functionality (like slicing), you have to write a bit more.

    The jagged array will use a bit more memory (after all, you have the overhead of 1M bitarray objects and 1K list objects), and may be a bit slower, but this usually won’t make much difference.

    The important deciding factor should be whether it’s inherently an error for your data to have jagged rows. If so, use the second solution; if it might be useful to have jagged or resizable rows, use the former. (Keeping in mind that I’d use numpy over either solution, if at all possible.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need my program to create and edit a config file, which would contain
I would like to remove all lines from a textfile which contain a certain
I would like to cycle through four li elements that all contain tags, setting
Basically i don't want to compare elements, but elements that thy contain. It would
I have to develop a table that would contain distance between destinations and need
In a non-AJAX web app, the URL would contain my view parameters (e.g. mysite?page=2&sort=name).
I want to make a registration page for clients, that would only contain a
I would like to validate IP addresses from a list that may contain incorrectly
I have a file that contain huge number of net names. I would like
I am using Ubuntu 9.10 beta, whose repositories contain boost 1.38. I would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.