A Visual Intro to NumPy and Data Representation
jalammar.github.io
A Visual Intro to NumPy and Data Representation
1–10 of 23 posts
Re: A Visual Intro to NumPy and Data Representation
#2Also, nitpick but I can't hold it: Why isn't the MSE np.mean(np.square(predictions - labels)? That's even breez-ier!
Re: A Visual Intro to NumPy and Data Representation
#3Re: A Visual Intro to NumPy and Data Representation
#4Re: A Visual Intro to NumPy and Data Representation
#5Pretty, but not particularly in-depth. Also, nitpick but I can't hold it: Why isn't the MSE np.mean(np.square(predictions - labels)? That's even breez-ier!
Re: A Visual Intro to NumPy and Data Representation
#6Re: A Visual Intro to NumPy and Data Representation
#7Take for example:
In [2]: numpy.array([1, 2, 3])[[0, 2, 1]]
Out[2]: array([1, 3, 2])
You index using a list and it gives you a view of the array with the new order (the underlying array is not changed and there is no copy being done).Re: A Visual Intro to NumPy and Data Representation
#8Re: A Visual Intro to NumPy and Data Representation
#9This is excellent. I'd love to see even more on Pandas.
https://jalammar.github.io/gentle-visual-intro-to-data-analy...
Re: A Visual Intro to NumPy and Data Representation
#10Nice overview! One thing I think you should add, which I find immensely useful is the reordering of arrays using indexing. Take for example: In [2]: numpy.array([1, 2, 3])[[0, 2, 1]] Out[2]: array([1, 3, 2]) You index using a list and it gives you a view of the array with the new order (the underlying array is not changed and there is no copy being done).
https://scipy-cookbook.readthedocs.io/items/ViewsVsCopies.ht...
You can verify there's a copy by changing the new array after putting the result in a new variable (see above link for why this makes a difference) and verifying the old one is unchanged:
>>> import numpy as np
>>> x = np.array([1, 2, 3])
>>> y = x[[0, 2, 1]]
>>> y[0] = 3
>>> y
array([3, 3, 2])
>>> x
array([1, 2, 3])
Edit:But a view can be based on a slice that includes a skip parameter, and in fact you even slice in multiple dimensions and it will still be a view. That is worth discussing in the article:
>>> x = np.array([np.arange(7), np.arange(7)+1]*3)
>>> y = x[4:1:-2, 1:5:2]
>>> y
array([[1, 3],
[1, 3]])
>>> y[0,0] = 99
>>> x
array([[ 0, 1, 2, 3, 4, 5, 6],
[ 1, 2, 3, 4, 5, 6, 7],
[ 0, 1, 2, 3, 4, 5, 6],
[ 1, 2, 3, 4, 5, 6, 7],
[ 0, 99, 2, 3, 4, 5, 6],
[ 1, 2, 3, 4, 5, 6, 7]])