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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:24:47+00:00 2026-05-19T01:24:47+00:00

Is it possible to create an .npy file without allocating the corresponding array in

  • 0

Is it possible to create an .npy file without allocating the corresponding array in memory first?

I need to create and work with a large numpy array, too big to create in memory. Numpy supports memory mapping, but as far as I can see my options are either:

  1. Create a memmapped file using numpy.memmap. This creates the file directly on disk without allocating memory, but doesn’t store the metadata, so when I re-map the file later I need to know its dtype, shape, etc. In the following, notice that not specifying the shape results in the memmap being interpreted as flat array:

    In [77]: x=memmap('/tmp/x', int, 'w+', shape=(3,3))
    
    
    In [78]: x
    Out[78]: 
    memmap([[0, 0, 0],
           [0, 0, 0],
           [0, 0, 0]])
    
    
    In [79]: y=memmap('/tmp/x', int, 'r')
    
    
    In [80]: y
    Out[80]: memmap([0, 0, 0, 0, 0, 0, 0, 0, 0])
    
  2. Create an array in memory, save it using numpy.save, after which it can be loaded in memmapped mode. This records metadata with the array data on disk, but requires that memory be allocated for the entire array at least once.

  • 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-19T01:24:48+00:00Added an answer on May 19, 2026 at 1:24 am

    I had the same question and was disappointed when I read Sven’s reply. Seems as though numpy would be missing out on some key functionality if you couldn’t have a huge array on file and work on little pieces of it at a time. Your case seems to be close to one of the use cases in the origional rational for making the .npy format (see: http://svn.scipy.org/svn/numpy/trunk/doc/neps/npy-format.txt).

    I then ran into numpy.lib.format, which seems to be full useful goodies. I have no idea why this functionality is not available from the numpy root package. The key advantage over HDF5 is that this ships with numpy.

    >>> print numpy.lib.format.open_memmap.__doc__
    
    """
    Open a .npy file as a memory-mapped array.
    
    This may be used to read an existing file or create a new one.
    
    Parameters
    ----------
    filename : str
        The name of the file on disk. This may not be a filelike object.
    mode : str, optional
        The mode to open the file with. In addition to the standard file modes,
        'c' is also accepted to mean "copy on write". See `numpy.memmap` for
        the available mode strings.
    dtype : dtype, optional
        The data type of the array if we are creating a new file in "write"
        mode.
    shape : tuple of int, optional
        The shape of the array if we are creating a new file in "write"
        mode.
    fortran_order : bool, optional
        Whether the array should be Fortran-contiguous (True) or
        C-contiguous (False) if we are creating a new file in "write" mode.
    version : tuple of int (major, minor)
        If the mode is a "write" mode, then this is the version of the file
        format used to create the file.
    
    Returns
    -------
    marray : numpy.memmap
        The memory-mapped array.
    
    Raises
    ------
    ValueError
        If the data or the mode is invalid.
    IOError
        If the file is not found or cannot be opened correctly.
    
    See Also
    --------
    numpy.memmap
    """
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Create a file in /system directory First of all, i gave the
Is possible create something like this without using ActionBar? I just need button which
Possible Duplicate: Create an Array of the Last 30 Days Using PHP I am
Possible Duplicate: Create Excel file in Java How to save output in excel format
Possible Duplicate: Create new C++ object at specific memory address? I am writing what
Is it possible to create an SSIS package that can be passed a file
Possible Duplicate: How can I create a temp file with a specific extension with
Is it possible to create a new array in windows workflow? More specifically, in
Is it possible to create an object that is @RooSolrSearchable without being a JPA
Possible Duplicate: Create a CSV File for a user in PHP Even though title

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.