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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:27:12+00:00 2026-06-11T11:27:12+00:00

I am translating a Matlab function to Python. Unfortunately I am not a Matlab

  • 0

I am translating a Matlab function to Python. Unfortunately I am not a Matlab expert and it is hard for me to understand some lines, e. g. this one:

a = [[0, 1]; [2, 3]]
bsxfun(@rdivide, sqrt(a), a)

I did not really understand it yet, but I think this line does

r / a

for each row r of sqrt(a) (or is it each column?) and r / sqrt(a) can usually be translated to numpy as

numpy.linalg.solve(sqrt(a).T, r.T).T

The problem with this is: Matlab says the result is

       NaN   1.00000
   0.70711   0.57735

and numpy says it is

[ 1.  0.]
[ 0.55051026  1.41421356]

which was generated by

for i in range(2): print linalg.solve(sqrt(a).T, a[i, :].T).T

Where is the error? The matrices sqrt(a) and a are just examples. You can replace them by any other matrix. I am just trying to understand what bsxfun does with rdivide.

  • 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-11T11:27:13+00:00Added an answer on June 11, 2026 at 11:27 am
    >>> import numpy as np
    >>> a = np.array([[0,1],[2,3]])
    >>> a
    array([[0, 1],
           [2, 3]])
    >>> b = np.sqrt(a)
    >>> b/a
    Warning: invalid value encountered in divide
    array([[        nan,  1.        ],
           [ 0.70710678,  0.57735027]])
    >>>
    

    Since you need an element-wise division, not matrix multiplication by the inverse, numpy.linalg is not what you want.

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

Sidebar

Related Questions

I'm working on translating some php code to Python. I'm not an expert in
I'm translating some stuff from MATLAB to the Python language. There's this command, unique(a),
I am translating some python code to Matlab, and want to figure out what
I'm translating some code from MATLAB to Python and I'm stuck with the corrmtx()
I'm translating some C# code to Delphi, I understand that(msg = TMsg): (int)msg.LParam is
Nota: this is not a duplicate of Translating PHP date() for Multilingual Site .
I'm translating some code from the DataContractSerializer to the impressive protobuf-net serializer, and one
I need help with translating some code from VB to C#. Public Function ToBase36(ByVal
I'm translating some Delphi code into c# code when I ran into this. I
I am translating some code from lisp to Python. In lisp, you can have

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.