Skip to content
Advertisement

matlab equivalent of dot star in python

I am working on a matlab conversion code. what is equivalent of .* in matlab with python?

len = sum(sqrt(sum(v.*v)))/N;

where v is numpy array :

v =  [array([-35289.38919481, -30575.56015338, -21456.41798462, ...,
    19796.17331542,  11216.34277023,   6977.87432284])]
N = 18225

In such cases, how will I convert code to python?

Advertisement

Answer

For numpy arrays, just using * will do the element-wise multiplication as in Matlab’s .* Link

you can use,

len = numpy.sum(numpy.sqrt(numpy.sum(v[0] * v[0], axis=0))) / N 

Note: If you want to use matrices instead of arrays in numpy, you have to use the multiply method.

Advertisement