Why does my code not work for axis = 1: I want to stanardize a matrix | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Why does my code not work for axis = 1: I want to stanardize a matrix

See my prog and change axis to 1 https://code.sololearn.com/cA12a0A14a12/#py

7th Jun 2021, 2:41 PM
Oma Falk
Oma Falk - avatar
6 Answers
+ 2
My guess: The dimensions of A and mean and std don't match, so you are trying to perform an operation that is not defined for matrix calculation. (What is your in trying to standardize this array by column?)
7th Jun 2021, 3:23 PM
Lisa
Lisa - avatar
+ 2
Axis: "[...] Note, that this only works with the first dimension, otherwise the shapes will not match for broadcasting. If you want to normalize wrt another axis you need to do something like: x -= np.expand_dims(np.mean(x,axis = n),n)" https://stackoverflow.com/questions/45834276/numpyzero-mean-data-and-standardization
7th Jun 2021, 3:29 PM
Lisa
Lisa - avatar
+ 2
Ich versteh kein Wort.., Erkläre mir bitte den zweiten Teil.... da drückt der Schuh, das möchte ich verstehen. I am newbie to this please explain part 2 in detail.
7th Jun 2021, 4:00 PM
Oma Falk
Oma Falk - avatar
+ 2
Lisa u know the spotify dataset?
7th Jun 2021, 4:38 PM
Oma Falk
Oma Falk - avatar
0
If you wanted to do it "the other way round, you could np.transpose(A) before doing any further calculations. (See code) I did not test if/how the quoted code works. Just wanted to highlight the paragraph. Aber mal aus Anwendungsperspektive: Normalerweise bedeuten die Zahlen ja irgendwas. Die Konvention ist Spalten = abhängige Variablen/Messungen, Zeilen = Beobachtungseinheiten, z.B. Frogged, Lisa, Harry Potter... Axis=1: In welchem Fall würde man nach Personen standardisieren wollen??? Ich nehme an, numpy hat v.a. die default Anwendungsfälle im Blick. https://code.sololearn.com/cAJb9w8b5zIf/?ref=app
7th Jun 2021, 4:09 PM
Lisa
Lisa - avatar
0
Frogged Which course? I haven't done it all yet... edit: I added some comments in my code.
7th Jun 2021, 4:39 PM
Lisa
Lisa - avatar