Understand it better #265
-
Lesson: https://github.com/microsoft/ML-For-Beginners/tree/main/2-Regression/1-Tools I have gone thorough the lesson in the last week a couple of times. Yet, I have some questions or doubts, that I may need some clarity upon. X = X[:, np.newaxis, 2] How does this specific line work? I have gone through the some of the numpy library, tried searching on Github. But have not been able to find a satisfactory answers. From what I got from Stack Overflow it tells that |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 14 replies
-
Hi,
Let me explain you import numpy as np
arr = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
print(arr) Here the output will be: [[ 1 2 3 4 5]
[ 6 7 8 9 10]] But, when you do import numpy as np
arr = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
print(arr[:, np.newaxis, 2]) Here, the output will be: [[3]
[8]] I think the above shown example will help you better understand the use of |
Beta Was this translation helpful? Give feedback.
-
I always get stuck whenever I'm trying do some data analysis before actually building a model. |
Beta Was this translation helpful? Give feedback.
-
@jlooper @abhi-bhatra |
Beta Was this translation helpful? Give feedback.
Hi,
This line takes the second element from all the columns of array
X
and creates a new array for you with new dimensions.X
, its shape was (442, 10)np.newaxis
for array slicing, its shape will be (442, 1)Let me explain you
np.newaxis
works with a simple example:Here the output will be:
But, when you do
np.newaxis
slicing:Here, the output will be:
I think the above shown example will help you better understand the us…