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…
NumPy Exercises for Data Analysis in Python
11–20 of 34 posts
Re: NumPy Exercises for Data Analysis in Python
#12Does 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.
Re: NumPy Exercises for Data Analysis in Python
#13This 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"...
Re: NumPy Exercises for Data Analysis in Python
#14Re: NumPy Exercises for Data Analysis in Python
#15For #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
#16Re: NumPy Exercises for Data Analysis in Python
#17One 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
#18One 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
#19One 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
#20This 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/