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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:24:37+00:00 2026-06-12T16:24:37+00:00

I am experimenting with some 3d rendering in Python. I keep reading that Python

  • 0

I am experimenting with some 3d rendering in Python. I keep reading that Python is soooooooo very slow! I simply MUST harness the C-awesomeness of Numpy for all the matrix stuff I can’t do in the shaders! Otherwise nothing will work, yadda, yadda (paraphrasing here..).

BUT: I did some testing!

Here’s a random matrix, once in Numpy-flavour:

matrix1 = numpy.matrix([[1, 1, 0, 0,], [0, 1, 0, 0], [0, 0, 1, 1], [0, 0, 0, 1]])
>>> matrix([[1, 1, 0, 0],
            [0, 1, 0, 0],
            [0, 0, 1, 1],
            [0, 0, 0, 1]])

and once as a bog-standard tuple:

matrix2 = (1, 1, 0, 0,\
      0, 1, 0, 0,\
      0, 0, 1, 1,\
      0, 0, 0, 1)

Now, if I want the inverse of that, I can either do it in Numpy:

def inv_1():
    return matrix1.I

or as pure Python (I omitted some of the maths because it hurts my head):

def inv_2():
    m0, m1, m2, m3, \
    m4, m5, m6, m7, \
    m8, m9, m10, m11, \
    m12, m13, m14, m15 = matrix2

    A0 = (( m0 *  m5) - ( m1 *  m4))  ....
 ...B5 = ((m10 * m15) - (m11 * m14))

    det = 1.0 / det
    return (
        (+ ( m5 * B5) - ( m6 * B4) + ( m7 * B3)) * det, ...
     ...(+ ( m8 * A3) - ( m9 * A1) + (m10 * A0)) * det
    )

both work fine:

inv_1()
>>>> matrix([[ 1., -1.,  0.,  0.],
             [ 0.,  1.,  0.,  0.],
             [ 0.,  0.,  1., -1.],
             [ 0.,  0.,  0.,  1.]])

inv_2()
>>>> (1.0, -1.0, 0.0, 0.0, 
      0.0, 1.0, 0.0, 0.0, 
      0.0, 0.0, 1.0, -1.0,
      0.0, 0.0, 0.0, 1.0)   (I added the line-breaks here for clarity)

But the pure Python code runs consistently about ten times faster than the highly praised Numpy:

timeit.timeit(inv_1, number=100000)
>>>> 3.0659120082855225

timeit.timeit(inv_2, number=100000)
>>>> 0.4014430046081543

And if you add the overhead of converting my beautiful tuple-matrices into Numpy matrices it will be even slower.

So what’s going on here? Am I doing something wrong? Is it all due to the overhead of invoking a C-function? Did the guy who’s inversion-code I stole break the laws of physics?

Thanks for de-noobing me! Love you all!

  • 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-12T16:24:38+00:00Added an answer on June 12, 2026 at 4:24 pm

    You’re inverting the matrix analytically (which is possible since you know the dimensions and since they’re not too big). numpy must invert the matrix using some other (numerical) algorithm which works if the matrix is 4×4 as well as 10000×10000. In other words, the general problem is much harder than the simple 4×4 case that you have.

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

Sidebar

Related Questions

I'm experimenting with some multithreading constructions, but somehow it seems that multithreading is not
I am doing some experimenting with robotics and have a USB servo controller that
I was experimenting with some examples and came across a problem that if we
I am doing some experimenting (so the code below has lots of stuff that
I have been experimenting some problems with the fully distributed version. First of all
I'm currently experimenting with some RESTful JAX and I want to validate a custom
I'm doing some experimenting with HttpWebRequest, and need to get it working with SSL.
I'm doing some experimenting with this malicious JavaScript line: var undefined = true; Every
I am currently working through Michael Hartl's Rails Tutorial while experimenting with some other
I was experimenting with toCharArray() and found some strange behavior. Suppose private static final

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.