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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:59:19+00:00 2026-06-06T01:59:19+00:00

This specific questions stems from the attempt to handle large data sets produced by

  • 0

This specific questions stems from the attempt to handle large data sets produced by a MATLAB algorithm so that I can process them with python algorithms.

Background: I have large arrays in MATLAB (typically 20x20x40x15000 [i,j,k,frame]) and I want to use them in python. So I save the array to a *.mat file and use scipy.io.loadmat(fname) to read the *.mat file into a numpy array. However, a problem arises in that if I try to load the entire *.mat file in python, a memory error occurs. To get around this, I slice the *.mat file into pieces, so that I can load the pieces one at a time into a python array. If I divide up the *.mat by frame, I now have 15,000 *.mat files which quickly becomes a pain to work with (at least in windows). So my solution is to use zipped files.

Question: Can I use scipy to directly read a *.mat file from a zipped file without first unzipping the file to the current working directory?

Specs: Python 2.7, windows xp

Current code:

import scipy.io
import zipfile
import numpy as np

def readZip(zfilename,dim,frames):
    data=np.zeros((dim[0],dim[1],dim[2],frames),dtype=np.float32)
    zfile = zipfile.ZipFile( zfilename, "r" )
    i=0
    for info in zfile.infolist():
        fname = info.filename
        zfile.extract(fname)
        mat=scipy.io.loadmat(fname)
        data[:,:,:,i]=mat['export']
        mat.clear()
        i=i+1
    return data

Tried code:

mat=scipy.io.loadmat(zfile.read(fname))

produces this error:

TypeError: file() argument 1 must be encoded string without NULL bytes, not str

mat=scipy.io.loadmat(zfile.open(fname))

produces this error:

fileobj.seek(0)
UnsupportedOperation: seek

Any other suggestions on handling the data are appreciated.

Thanks!

  • 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-06T01:59:21+00:00Added an answer on June 6, 2026 at 1:59 am

    I am pretty sure that the answer to my question is NO and there are better ways to accomplish what I am trying to do.

    Regardless, with the suggestion from J.F. Sebastian, I have devised a solution.

    Solution: Save the data in MATLAB in the HDF5 format, namely hdf5write(fname, '/data', data_variable). This produces a *.h5 file which then can be read into python via h5py.

    python code:

    import h5py
    
    r = h5py.File(fname, 'r+')
    data = r['data']
    

    I can now index directly into the data, however is stays on the hard drive.

    print data[:,:,:,1]
    

    Or I can load it into memory.

    data_mem = data[:]
    

    However, this once again gives memory errors. So, to get it into memory I can loop through each frame and add it to a numpy array.

    h5py FTW!

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

Sidebar

Related Questions

This stems from a related discussion, How to subtract specific elements in a list
I have seen several similar questions to this, but none that addresses my specific
First of I'm very sorry but this questions is not so so specific. All
I am looking to create a QTcpServer using PyQt that can simultaneously return data
I have been googling a lot about this, but I can't find a specific
MSDN is rather vague regarding this attribute. The custom data string can be set
This is a very specific questions about the steps necessary to Build a simple
This is a very specific questions about the steps necessary to Build a simple
This question stems from watching Rasmus Lerdorf's talk from Drupalcon . This question and
This is a very specific question which will probably earn me the tumbleweed badge,

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.