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

  • SEARCH
  • Home
  • 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 6252499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:48:46+00:00 2026-05-24T13:48:46+00:00

I am using Python and Numpy to do some data analysis. I have a

  • 0

I am using Python and Numpy to do some data analysis.

I have a large 3D matrix (NxNxN), where each cell is again a matrix, this time a 3×3 matrix. Calling the matrix data, it looks like this:

data[N,N,N,3,3]  

I need to find the eigenvalues of all the 3×3 matrices, and for that I use Numpy’s eigvals routine, but it takes ages to do. Right now I pretty much do this:

for i in range(N):
    for j in range(N):
        for k in range(N):
            a = np.linalg.eigvals(data[i,j,k,:,:])

For N = 256, this takes about an hour. Any ideas on how to make this more efficient?

Many thanks for any suggestions!

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

    itertools.product is nicer than nested loops, aesthetically speaking. But I don’t think it will make your code that much faster. My testing suggests that iteration is not your bottleneck.

    >>> bigdata = numpy.arange(256 * 256 * 256 * 3 * 3).reshape(256, 256, 256, 3, 3)
    >>> %timeit numpy.linalg.eigvals(bigdata[100, 100, 100, :, :])
    10000 loops, best of 3: 52.6 us per loop
    

    So underestimating:

    >>> .000052 * 256 * 256 * 256 / 60
    14.540253866666665
    

    That’s 14 minutes minimum on my computer, which is pretty new. Let’s see how long the loops take…

    >>> def just_loops(N):
    ...     for i in xrange(N):
    ...         for j in xrange(N):
    ...             for k in xrange(N):
    ...                 pass
    ... 
    >>> %timeit just_loops(256)
    1 loops, best of 3: 350 ms per loop
    

    Orders of magnitude smaller, as DSM said. Even the work of slicing the array alone is more substantial:

    >>> def slice_loops(N, data):
    ...     for i in xrange(N):
    ...         for j in xrange(N):
    ...             for k in xrange(N):
    ...                 data[i, j, k, :, :]
    ... 
    >>> %timeit slice_loops(256, bigdata)
    1 loops, best of 3: 33.5 s per loop
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using MySQLdb and Python. I have some basic queries such as this: c=db.cursor()
Using python 2.4 and the built-in ZipFile library, I cannot read very large zip
When using Python's super() to do method chaining, you have to explicitly specify your
I am using python 2.6 on XP. I have just installed py2exe, and I
I am developing a Python package for dealing with some scientific data. There are
I have a 256x256 numpy-array of data which is constantly being changed. on every
I'm looking into speeding up my python code, which is all matrix math, using
Using Python I want to be able to draw text at different angles using
Using Python, how would I go about reading in (be from a string, file
Using Python 2.6, is there a way to check if all the items of

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.