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 4618664
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:17:57+00:00 2026-05-22T02:17:57+00:00

I want to create a matrix with Numpy in Python with the following code:

  • 0

I want to create a matrix with Numpy in Python with the following code:

import numpy

result=numpy.zeros((20,20,20,30,30,30))

numpy.save('result',result)

I get the following error:

Traceback (most recent call last):  
File "numpy_memoryerror.py",
line 5, in <module>
    result=numpy.zeros((20,20,20,30,30,30))
MemoryError

If I use smaller dimensions like these:

result=numpy.ones((10,10,10,20,20,20))

then the code works.

Can somebody tell me the limit of the shape tuple?

  • 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-05-22T02:17:58+00:00Added an answer on May 22, 2026 at 2:17 am

    Its not a fundamental limit of the shape tuple, its that you don’t have enough memory (RAM) on your system, hence the MemoryError.

    Again 20*20*20*30*30*30 is 216 million 64-bit (8 byte) floats or a little more than 1.6 GB of RAM. So do you have 1.6 GB of RAM free while running the script at that point? (Don’t forget to all the RAM used by python, the OS, other running programs, etc.). If you are in linux/unix you can see how much free memory by typing free -m from the command prompt. In windows you can see free memory by going to the task manager. Furthermore, some OSes limit the amount of memory that a single process (like python) can allocate; e.g., 32-bit windows only gives 2 GB of address space per process).

    Compare that to 20*20*20*10*10*10, which is only ~0.06 GB (or just 27 times less memory).

    If you don’t need 8-byte floats, you could do

    numpy.zeros(20,20,20,30,30,30, dtype='float32')
    

    which would halve your memory footprint by using single-precision (32-bit) floats. By default numpy uses dtype=’float64′.

    Roughly speaking a 32-bit float has 8 digits of accuracy, a 64-bit float has 16 digits of accuracy. Meaning that 1+1e-8 appears as just 1 for 32-bit floats, and 1+1e-16 appears as 1 for 64-bit floats, but 1+1e-15 appears as 1.000000000000001 with 64-bit floats, but not 32-bit floats.

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

Sidebar

Related Questions

I have written a code in Python to create a transition probability matrix from
I want to create an allocator which provides memory with the following attributes: cannot
I want create texture atlas(matrix of images) from multiple images.Is their any applescript that
I want to create a current,30, 60, 90, day aging reports in Matrix Format
vector= 3 4 8 5 2 1 6 the matrix i want to create
I have a matrix and i want to create a new matrix which will
I want to increment a small subsection (variable) of an matrix [illustrative code below]
I want to create a matrix representation for a graph algorithm using the least
I want to create a matrix A [4x8] as follows. The matrix A always
I want to create images like this from a double precision matrix using MATLAB.

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.