+ 2
Do the rows or the columns count for dimensions of a Matrix in NumPy?
The question may sound off topic and silly but I really want to know what exactly does signify the dimension in a numpy matrix - Rows or Columns? I have been following 3B1Bs series on Linear Algebra but I still strive harder when I comeback to learn numpy. :( The short example might ease things down. let there be a numpy array given as >>> x = np.array([[5, 2, 3], [2, 3, 2]]) >>> x.ndim [out] 2 This means (to my knowledge) that there are 2 dimension - obviously rows here. This confuses me because many YouTubers, books and especially 3b1b uses columns as dimension of the matrix! Thanks for the help!
6 Réponses
+ 1
I've only just glanced over numpy....the dimensions means (sort of) now "deep" they are nested.
c = np.array([[[1, 2, 3]]])
print(c.ndim) ...output = 3;
+ 5
DarkRanger , this a link to a sololearn tutorial, that may cover your question:
https://www.sololearn.com/learn/6671/?ref=app
+ 1
Count of rows does not signify dimensions
c = np.array([[1, 2, 3], [4, 5, 6], [7 ,8, 9]])
print(c.ndim)..... output = 2.
0
>import numpy as np
>b = np.array([1, 2, 3, 4])
Thanks Lothar, but as you can see, the question isnt addressed there either. My view is that the b should be 4 dimensional because there are 4 columns. I might be wrong but all Books use columns as a count of dimension of a Matrix.
0
Thanks rodwynnejones,it makes sense that rows dont signify the dimension of matrix but I got even more confused as why it is 2 dimensions when there are 3 rows, and 3 columns. Does numpy use different aporoach or these arent fundamentally matrices?
0
rodwynnejones thanks for the clarification. I think I skimmed over that part. Makes sense now!