Python Numpy Array visual representation | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Python Numpy Array visual representation

With below 2 linked images, which is the "correct" visualization of numpy 1d array? First: elements are placed horizontally https://nustat.github.io/DataScience_Intro_python/Datasets/numpy_image.png Second: elements are placed vertically https://storage.googleapis.com/lds-media/images/numpy-vector-matrix-3d-matrix.width-1200.jpg I thought the second is much easier to understand as axis 0 always pointing the same direction, while majority use the first image as I searched. Is it because the console output is the same as the second image? Also, the first image says it is Vector, not 1D array. Is there any difference between Vector and 1D array?

7th Feb 2024, 1:36 PM
Wong Hei Ming
Wong Hei Ming - avatar
6 Answers
+ 3
a vector here refers to the mathematical term. you can think of vectors as 1D arrays but vectors can a) be row vectors or b) be column vectors. when operating with vectors or 1d arrays you need to be aware of the shape of the objects.
7th Feb 2024, 1:56 PM
Lisa
Lisa - avatar
+ 3
vectors (and matrices) are mathematical terms. arrays are informatics terms. when doing math with vectors, the direction of the vectors matter. a column vector (North South) is not the same as a row vector (East West) when applying mathematical operations: The shape matters because a given operation may not be defined for different shape-combinations. https://sololearn.com/compiler-playground/cl0uYGyE1s0U/?ref=app
7th Feb 2024, 5:43 PM
Lisa
Lisa - avatar
+ 2
does it have anything to do with row-major or column-major? https://stackoverflow.com/questions/20341614/numpy-array-row-major-and-column-major
9th Feb 2024, 10:40 AM
Bob_Li
Bob_Li - avatar
+ 1
Lisa For example, I created a 1d array with: arr = np.array(range(5)) # [0 1 2 3 4] print(arr.shape) # (5, ) print(arr.shape[0]) # 5 The first print told us the shape of the object has one axis only, with a size of five. And the second told us the shape (size) of axis 0 is five. To me, 1d is like a line. It can be east-west, north-south or any direction with different angle, a line shape object. So, what is the meaning of "when operating with vectors or 1d arrays you need to be aware of the shape of the objects." as the shape always is a straight line?
7th Feb 2024, 4:42 PM
Wong Hei Ming
Wong Hei Ming - avatar
+ 1
My math knowledge is limited. In terms of describing an object, I can only use point, line, surface and 3D (stack of surfaces). To help myself understand numpy better, I think a visualized object can help. This is an image which captures my understanding, as I imagine we view an object from bird-eye view. https://i.ibb.co/D5kP3xX/blockout.png If my theory (bird-eye view) is correct, why almost all text material use a horizontal line representation to describe 1d array? If I’m wrong, then there must be some misunderstanding from me and I want to know what is it.
8th Feb 2024, 8:03 AM
Wong Hei Ming
Wong Hei Ming - avatar
+ 1
Bob_Li Interesting reading. Never thought about reshaping 1d array, and it clear my mind about Lisa's answer on column \ row vector. And it looks like the last picture I posted is mixing up axis 0 and 1.
9th Feb 2024, 3:23 PM
Wong Hei Ming
Wong Hei Ming - avatar