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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:54:29+00:00 2026-05-30T13:54:29+00:00

I am very new to Python. I need to have a 3 dimensional matrix,

  • 0

I am very new to Python. I need to have a 3 dimensional matrix, in order to save 8 by 8 matrix in some length. Let’s call 530. The problem is that I used np.array since matrix cannot have more than 2 dimensions as numpy argues.
R = zeros([8,8,530],float)
I calculated my 8 by 8 matrix as a np.matrix
R[:,:,ii] = smallR
And, then I try to save it in mat file as scipy claims to do so.
sio.savemat('R.mat',R)
However, error says ‘numpy.ndarray’ object has no attribute ‘items’

/usr/local/lib/python2.7/dist-packages/scipy/io/matlab/mio.py:266: FutureWarning: Using oned_as default value ('column') This will change to 'row' in future versions
oned_as=oned_as)

Traceback (most recent call last):
File "ClassName.py", line 83, in <module>
print (buildR()[1])

File "ClassName.py", line 81, in buildR
sio.savemat('R.mat',R)

File "/usr/local/lib/python2.7/dist-packages/scipy/io/matlab/mio.py", line 269, in savemat
MW.put_variables(mdict)

File "/usr/local/lib/python2.7/dist-packages/scipy/io/matlab/mio5.py", line 827, in put_variables
for name, var in mdict.items():
AttributeError: 'numpy.ndarray' object has no attribute 'items'

  • 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-30T13:54:30+00:00Added an answer on May 30, 2026 at 1:54 pm

    If you type help(sio.savemat), you see:

    savemat(file_name, mdict, appendmat=True, format='5', long_field_names=False, do_compression=False, oned_as=None)
        Save a dictionary of names and arrays into a MATLAB-style .mat file.
    [...]
        mdict : dict
            Dictionary from which to save matfile variables.
    

    and so even if you don’t recognize .items() as a dictionary method, it’s clear we’re going to need to use a dictionary (a set of key, value pairs; google “python dictionary tutorial” if necessary).

    In this case:

    >>> from numpy import zeros
    >>> from scipy import io as sio
    >>> 
    >>> R = zeros([8,8,530],float)
    >>> R += 12.3
    >>> 
    >>> sio.savemat('R.mat', {'R': R})
    >>> 
    >>> S = sio.loadmat('R.mat')
    >>> S
    {'R': array([[[ 12.3,  12.3,  12.3, ...,  12.3,  12.3,  12.3],
            [ 12.3,  12.3,  12.3, ...,  12.3,  12.3,  12.3],
            [ 12.3,  12.3,  12.3, ...,  12.3,  12.3,  12.3],
            ..., 
    
            ..., 
            [ 12.3,  12.3,  12.3, ...,  12.3,  12.3,  12.3],
            [ 12.3,  12.3,  12.3, ...,  12.3,  12.3,  12.3],
            [ 12.3,  12.3,  12.3, ...,  12.3,  12.3,  12.3]]]), '__version__': '1.0', '__header__': 'MATLAB 5.0 MAT-file Platform: posix, Created on: Sat Feb 25 18:16:02 2012', '__globals__': []}
    >>> S['R']
    array([[[ 12.3,  12.3,  12.3, ...,  12.3,  12.3,  12.3],
            [ 12.3,  12.3,  12.3, ...,  12.3,  12.3,  12.3],
            [ 12.3,  12.3,  12.3, ...,  12.3,  12.3,  12.3],
            ..., 
    
            ..., 
            [ 12.3,  12.3,  12.3, ...,  12.3,  12.3,  12.3],
            [ 12.3,  12.3,  12.3, ...,  12.3,  12.3,  12.3],
            [ 12.3,  12.3,  12.3, ...,  12.3,  12.3,  12.3]]])
    

    Basically, a dictionary is used so that the arrays can be named, as you can store multiple objects in one .mat file.

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

Sidebar

Related Questions

I am still very new to python, but I need to interface with some
I am very new to matlab and python and need to use some values
I very new to Python, and fairly new to regex. (I have no Perl
I'm very new to Python development, and am having a problem with one of
I am very new to python. I need to draw this shape for college
I am very new to Python and I have been trying to detect missing
I am very new to Python and have question. How in Python check if
I am trying to scrape some content (am very new to Python) and I
I'm very new to Python, but I need to migrate a project from PHP
I'm very new to python and I have a basic python script where I

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.