Live data from Hacker News

NumPy Exercises for Data Analysis in Python

machinelearningplus.com

11–20 of 34 posts

Re: NumPy Exercises for Data Analysis in Python

#11
post #7

There are some nice exercises here, good work. For question 48 it might be simpler to just write np.sort(a)[-5:] instead of using argsort() and then using fancy indexing. Better yet, use np.partition(a, kth=-5)[-5:] which scales linearly with the size of the array. Also, the one-hot encoding puzzle (51) would be more efficiently solved using (arr[:, None] == np.unique(arr)).view(np.int8) In general, `for` loops over…

Thanks for the suggestion, I will factor those in.

Re: NumPy Exercises for Data Analysis in Python

#12
post #9
post #8

Does anyone know of any similar resources for Pandas? I've found the following to be quite helpful but would love to know if anyone knows of other resources in a similar vein: https://pandas.pydata.org/pandas-docs/stable/cookbook.html

I started writing a '100-pandas-puzzles' set of exercises here: https://github.com/ajcr/100-pandas-puzzles There's also pandas_exercises by Guilherme Samora ( https://github.com/guipsamora/pandas_exercises ) which is very good - it's split across multiple notebooks and is more extensive than my repo.

Nice stuff!

Re: NumPy Exercises for Data Analysis in Python

#13
post #3

This is very similar in spirit to https://github.com/rougier/numpy-100/blob/master/100%20Numpy... . In fact, now that I look at it a bit more, it seems like all of this post's examples are reworded versions of Nicolas Rougier's "numpy 100"...

There's also Rosalind for bioinformatics problems to be solved in Python.

http://rosalind.info/problems/locations/

Re: NumPy Exercises for Data Analysis in Python

#15
Working through them and noticed a few small things.

For #3, you can make a boolean array with np.ones/np.zeros with the same dtype arg, saves a little bit of space.

ie np.ones((3,3), dtype=bool)

For #14, you can make use of the same compound boolean statements as you can in pandas to make it a bit simpler.

ie a[(a > 5) & (a For #15, this is a built in numpy function.

np.maximum(a,b).

That's as far as I've made it, but I'm really enjoying them.

Re: NumPy Exercises for Data Analysis in Python

#16
One thing that is holding me back in numpy is not knowing the runtime complexity of operations—of course I can profile code, but I should have better awareness when writing code in the first place. Without an algorithms background, I don't have strong intuitions on the runtime complexity of the primitives (np.unique). Any suggestions?

Re: NumPy Exercises for Data Analysis in Python

#17
post #16

One thing that is holding me back in numpy is not knowing the runtime complexity of operations—of course I can profile code, but I should have better awareness when writing code in the first place. Without an algorithms background, I don't have strong intuitions on the runtime complexity of the primitives (np.unique). Any suggestions?

What other library tells you about complexity? And as you tell, if you don't know algorithns well, I'm pretty sure your implementations won't have better complexity.

Re: NumPy Exercises for Data Analysis in Python

#18
post #16

One thing that is holding me back in numpy is not knowing the runtime complexity of operations—of course I can profile code, but I should have better awareness when writing code in the first place. Without an algorithms background, I don't have strong intuitions on the runtime complexity of the primitives (np.unique). Any suggestions?

Switch to Julia! Hit @edit unique([1,2,3,2]) in the REPL and you see the implementation.

Re: NumPy Exercises for Data Analysis in Python

#19
post #16

One thing that is holding me back in numpy is not knowing the runtime complexity of operations—of course I can profile code, but I should have better awareness when writing code in the first place. Without an algorithms background, I don't have strong intuitions on the runtime complexity of the primitives (np.unique). Any suggestions?

Switch to Julia! Hit @edit unique([1,2,3,2]) in the REPL and you see the implementation.

Nice! Ive been meaning to try out Julia for a while now. Is the numpy equivalent in Julia largely written in Julia itself? (as opposed to C/Fortran)

Re: NumPy Exercises for Data Analysis in Python

#20
post #13
post #3

This is very similar in spirit to https://github.com/rougier/numpy-100/blob/master/100%20Numpy... . In fact, now that I look at it a bit more, it seems like all of this post's examples are reworded versions of Nicolas Rougier's "numpy 100"...

There's also Rosalind for bioinformatics problems to be solved in Python. http://rosalind.info/problems/locations/

This looks interesting. Thanks for the link.
Post reply on HN