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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:35:34+00:00 2026-06-04T01:35:34+00:00

Using SciPy and MATLAB, I’m having trouble reconstructing an array to match what is

  • 0

Using SciPy and MATLAB, I’m having trouble reconstructing an array to match what is given from a MATLAB cell array loaded using scipy.io.loadmat().

For example, say I create a cell containing a pair of double arrays in MATLAB and then load it using scipy.io (I’m using SPM to do imaging analyses in conjunction with pynifti and the like)

MATLAB

>> onsets{1} = [0 30 60 90]
>> onsets{2} = [15 45 75 105]

Python

>>> import scipy.io as scio
>>> mat = scio.loadmat('onsets.mat')
>>> mat['onsets'][0]
array([[[ 0 30 60 90]], [[ 15  45  75 105]]], dtype=object)

>>> mat['onsets'][0].shape

(2,)

My question is this: Why does this numpy array have the shape (2,) instead of (2,1,4)? In real life I’m trying to use Python to parse a logfile and build these onsets cell arrays, so I’d like to be able to build them from scratch.

When I try to build the same array from the printed output, I get a different shape back:

>>> new_onsets = array([[[ 0, 30, 60, 90]], [[ 15,  45,  75, 105]]], dtype=object)
array([[[0, 30, 60, 90]],

       [[15, 45, 75, 105]]], dtype=object)

>>> new_onsets.shape
(2,1,4)

Unfortunately, the shape (vectors of doubles in a cell array) is coded in a spec upstream, so I need to be able to get this saved exactly in this format. Of course, it’s not a big deal since I could just write the parser in MATLAB, but it would be nice to figure out what’s going on and add a little to my [minuscule] knowledge of numpy.

  • 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-04T01:35:36+00:00Added an answer on June 4, 2026 at 1:35 am

    Travis from the scipy mailing list responded that the right way to build this is to create the structure first, then populate the arrays:

    http://article.gmane.org/gmane.comp.python.scientific.user/31760

    > You could build what you saw before with: 
    > 
    > new_onsets = empty((2,), dtype=object) 
    > new_onsets[0] = array([[0, 30, 60, 90]]) 
    > new_onsets[1] = array([[15, 45, 75, 105]])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the given routines (how to load Matlab .mat files with scipy), I could
I am on my transitional trip from MATLAB to scipy(+numpy)+matplotlib. I keep having issues
I am trying to do a fit to a given function using Scipy. Scipy.optimize.leastsq
I have been using the scipy.stats.invgamma.rvs function to randomly select values from an inverse
I'm relatively new to python and scipy, being a convert from MATLAB. I was
When load matrices from mat file in python using scipy.io , it makes dictionary
When using scipy.optimize 's fmin I'm getting an error I don't understand: ValueError: setting
I'm using scipy.linalg to solve a matrix equation A*x = b The following code
I am using Scipy to construct a large, sparse (250k X 250k) co-occurrence matrix
I am using scipy-cluster in my application. It provides a function to plot a

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.