Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

normalize multi dimensional numpy array

I have the following numpy array :

A = np.array([[1,2,3,4,5],
             [15,25,35,45,55]])

I would like to create a new array with the same shape by dividing each dimension by the last element of the dimension

The output desired would be :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

B = np.array([[0.2,0.4,0.6,0.8,1],
              [0.27272727,0.45454545,0.63636364,0.81818182,1]])

Any idea ?

>Solution :

You mean this?

B = np.array([[A[i][j]/A[i][len(A[i])-1] for j in range(0,len(A[i]))] for i in range(0,len(A))])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading