News for hackers. Stuff that matters.
Re:A Visual Intro to NumPy and Data Representation by lejar on Wednesday June 26, 2019 @07:38AM (#20283964)
Nice 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).
Re:A Visual Intro to NumPy and Data Representation by quietbritishjim on Wednesday June 26, 2019 @08:03AM (#20284096)
Using "fancy" indices like this does result in a copy because it can't be represented as a simple slice of the original matrix. A good explaination is here (it's from 2008 but still true):

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]])
Re:A Visual Intro to NumPy and Data Representation by improbable22 on Wednesday June 26, 2019 @02:35PM (#20287833)
A related fun fact, when slicing several dimensions:

    >>> a = np.arange(9).reshape(3,3) # a matrix
    >>> a[0:3,0:3]          # ranges are treated independently
    array([[0, 1, 2],
           [3, 4, 5],
           [6, 7, 8]])
    >>> a[[0,1,2],[0,1,2]]  # but arrays are treated at once
    array([0, 4, 8])
Re:A Visual Intro to NumPy and Data Representation by ovi256 on Wednesday June 26, 2019 @09:04AM (#20284530)
A copy-on-write mechanism triggered by `y[0] = 3` would look the same and pass the test you devised, so you can't eliminate the possibility that it exists.

A better way would be to track memory use. A copy being created by either `y = x[[0, 2, 1]]` or `y[0] = 3` would show as a memory increase.

Re:A Visual Intro to NumPy and Data Representation by jcims on Wednesday June 26, 2019 @12:55PM (#20286796)
As an aside, one of my major challenges grokking numpy and pandas is the semantically dense syntax like the above. I know that the layers of bracing have an impact but it's difficult for me to tell where it is applied and/or described.
Re:A Visual Intro to NumPy and Data Representation by grenoire on Wednesday June 26, 2019 @06:15AM (#20283516)
Pretty, 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 by manojlds on Wednesday June 26, 2019 @06:42AM (#20283639)
I think it's generally done this way because of the way the formula is represented mathematically.
Re:A Visual Intro to NumPy and Data Representation by milliams on Wednesday June 26, 2019 @06:18AM (#20283529)
I like this. One change I would make is on the aggregation and indexing section, change the representation of single values (as opposed to single-element arrays) to not be in a coloured box. It's important that the result of these operations is a different type.
Re:A Visual Intro to NumPy and Data Representation by pard68 on Wednesday June 26, 2019 @07:22AM (#20283865)
Numpy was a huge boon in college. I had mostly gotten my homework process down to editing a LaTeX file with the csv files for my datasets and then when I compiled it would first crunch the numbers with Numpy, export it as Tex, and then build a pdf.
Re:A Visual Intro to NumPy and Data Representation by alanbernstein on Wednesday June 26, 2019 @05:29PM (#20289396)
Care to share an example?
Re:A Visual Intro to NumPy and Data Representation by pard68 on Thursday June 27, 2019 @06:09AM (#20293075)
I might still have something. I didn't version control it, but it might be on Dropbox still.
Re:A Visual Intro to NumPy and Data Representation by dintech on Wednesday June 26, 2019 @07:56AM (#20284047)
This is excellent. I'd love to see even more on Pandas.
Re:A Visual Intro to NumPy and Data Representation by dintech on Wednesday June 26, 2019 @07:57AM (#20284056)
And now I see that you've already started one!

https://jalammar.github.io/gentle-visual-intro-to-data-analy...

Re:A Visual Intro to NumPy and Data Representation by iandanforth on Wednesday June 26, 2019 @02:08PM (#20287553)
It would be good to mention the @ operator in the matrix multiplication section.

https://alysivji.github.io/python-matrix-multiplication-oper...

Re:A Visual Intro to NumPy and Data Representation by improbable22 on Wednesday June 26, 2019 @02:25PM (#20287738)
A warning sign that your faith in 0-based indexing may be faltering -- catching yourself writing comments like this :)

    # element at the top right. i.e. (1, 2) aka (0, 1) in python
    A[0, 0] * B[0, 1] + A[0, 1] * B[1, 1]
Re:A Visual Intro to NumPy and Data Representation by iandanforth on Wednesday June 26, 2019 @03:04PM (#20288089)
That's called the "Matlab Hangover"
Re:A Visual Intro to NumPy and Data Representation by 1-6 on Thursday June 27, 2019 @11:42PM (#20301296)
Wow, this is so timely! I love the visual references. I'm still a little confused about the section on Matrix Indexing. Overall, great work!
Re:A Visual Intro to NumPy and Data Representation by Vaslo on Wednesday June 26, 2019 @08:44AM (#20284359)
Good stuff! I'll definitely look for more from you!
Re:A Visual Intro to NumPy and Data Representation by tjpaudio on Wednesday June 26, 2019 @05:12PM (#20289245)
Nice page, but unless you have never used software for math before, I am not sure it's very useful.
Re:A Visual Intro to NumPy and Data Representation by xvilka on Wednesday June 26, 2019 @10:02AM (#20285081)
Would be nice to have something like this, but for Julia.
Re:A Visual Intro to NumPy and Data Representation by improbable22 on Wednesday June 26, 2019 @12:50PM (#20286747)
There is this, though shorter: https://julia.guide/broadcasting