Live data from Hacker News

Help us collect modern Python NumPy code solutions

github.com

11–20 of 41 posts

Re: Help us collect modern Python NumPy code solutions

#11
I've added a comment to the issue How to plot a data frame https://github.com/Onelinerhub/onelinerhub/issues/1378#issue...

Actually concerning visualization tasks I don't see a sense in one line solution because as I think you should understand how you want to represent your data and this has strong influence to calling signatures.

Re: Help us collect modern Python NumPy code solutions

#12
post #3

For almost all issues, you can simply search for site:stackoverflow.com + the title of the issue and get a larger variety of solutions ranked by upvotes, so this repository seems strictly worse. Is there any advantage that this repository brings over just searching for the question on StackOverflow?

I didn’t review all of the code, but the examples I saw seemed to have some basic explanations with them. Additionally, they have samples for a lot of different technologies. A curated repo seems much nicer than scoring several StackOverflow answers. Depends on the code quality, of course.

The code quality seems questionable. A few examples:

Repository claims modern code, but uses Python 2 (end of life January 1, 2020) https://github.com/Onelinerhub/onelinerhub/blob/main/python/... Copied from https://wiki.python.org/moin/Powerful%20Python%20One-Liners

Incorrect indentation causing unnecessarily large memory usage https://github.com/Onelinerhub/onelinerhub/blob/main/python/...

Undefined behavior for i = 31 https://github.com/Onelinerhub/onelinerhub/blob/main/c/bits_...

Printing of uninitialized memory https://github.com/Onelinerhub/onelinerhub/blob/main/c/set_v...

Undefined behavior https://github.com/Onelinerhub/onelinerhub/blob/main/c/swap_...

Re: Help us collect modern Python NumPy code solutions

#13
post #8

For almost all issues, you can simply search for site:stackoverflow.com + the title of the issue and get a larger variety of solutions ranked by upvotes, so this repository seems strictly worse. Is there any advantage that this repository brings over just searching for the question on StackOverflow?

The README explains that they want a single curated answer, not a list of 15 answers with 25 comments. This does seem worthwhile, at least for some types of questions.

Isn't the "curated" answer on Stack Overflow the answer with most votes?

Sure, sometimes the top voted answer is not the answer to my particular problem at hand, but if it isn't, I'd rather have more alternative answers than nothing.

Re: Help us collect modern Python NumPy code solutions

#14
post #3

Earlier quoted context omitted.

I didn’t review all of the code, but the examples I saw seemed to have some basic explanations with them. Additionally, they have samples for a lot of different technologies. A curated repo seems much nicer than scoring several StackOverflow answers. Depends on the code quality, of course.

The code quality seems questionable. A few examples: Repository claims modern code, but uses Python 2 (end of life January 1, 2020) https://github.com/Onelinerhub/onelinerhub/blob/main/python/... Copied from https://wiki.python.org/moin/Powerful%20Python%20One-Liners Incorrect indentation causing unnecessarily large memory usage https://github.com/Onelinerhub/onelinerhub/blob/main/python/... Undefined behavior for i…

Fixed some of those. Simple case of just pushing the edit button and sending a PR.

Re: Help us collect modern Python NumPy code solutions

#15
post #6
post #3

Earlier quoted context omitted.

I didn’t review all of the code, but the examples I saw seemed to have some basic explanations with them. Additionally, they have samples for a lot of different technologies. A curated repo seems much nicer than scoring several StackOverflow answers. Depends on the code quality, of course.

I looked at the C# ones - the code is not great and neither are the explanations, both show a lack of experience in C# and .NET. How to reverse the characters in a string String.Join("",("1234Simple").Select(c=>c).Reverse()); - String.Join("", - concatenate one or more characters in a single list or array, by using empty "" string literal separator - .Select(c=>c) - select each and every other character in a string i…

Indeed, their example is terrible, because it's also the kind of 'toy' problem that just doesn't have good real world uses too.

How often do you want to reverse a string.

I think your solution is fine and isn't "bad code" at all. Certainly a real explanation warrants talking about the IEnumerable interface.

I'd also consider the simpler (and ever so slightly better performing):

    var buffer = "1234simple".ToArray();
    Array.Reverse(buffer);
    new string(buffer);
edit: The following is dramatically (x10) even better performing:

    var buffer = "1234simple".ToCharArray();
    Array.Reverse(buffer);
    new string(buffer);
But again with the caveat of that not respecting unicode sequences.

But to re-iterate and to add to your criticism, I can't understand the use-case of needing to do this outside of toy problems.

Re: Help us collect modern Python NumPy code solutions

#16
Some of these problems don't really have much information / specs.

"Generate random array" (python-numpy)"

Ok - but what dimension? size/length? what range? sample from what distribution? only unique values? etc.

Many of these problems have "native" one-liner numpy solutions which are trivial to find (basically just read the documentation).

Re: Help us collect modern Python NumPy code solutions

#17

I learned J before NumPy and I'm glad I did, because it's much easier to see and learn the algorithms when they're short symbols. Compare np.sqrt(sum(np.square(x))) versus %: +/ *: x So if you can translate one of the array languages to NumPy, you can tap into the wealth of "idioms" collected over the years. For example: J Phrases[0] (organized by category), BQNcrate[1] and APLcart[2] (searchable). [0]: https://www.j…

I think a fairer comparison would be

    np.linalg.norm(x)
or even

    norm(x)
if you

    import numpy.linalg.norm as norm
beforehand. This comes with the advantage that you can look up the function by name to know what it does instead of having to look up chains of symbols on several websites.

Re: Help us collect modern Python NumPy code solutions

#18
post #4

#write a function that zips numpy arrays import numpy as np def zip_arrays(arrays): return np.array([np.concatenate(arr) for arr in zip(*arrays)])

>>> arrays = [np.arange(1000)]*10 >>> zip_arrays(arrays) Traceback (most recent call last): File " ", line 1, in File " ", line 2, in zip_arrays2 File " ", line 2, in File " ", line 180, in concatenate ValueError: zero-dimensional arrays cannot be concatenated Try this: def zip_arrays(arrays): return np.concatenate([array[:l,...,None] for l in [min(array.shape[0] for array in arrays)] for array in arrays], axis=-1) O…

I think a more Pythonic solution would be

    np.array(arrays).T
or maybe

    np.copy(arrays).T
for one less character. The shortest solution is probably

    np.c_[arrays].T
but likely causes a Google search on first read.

Re: Help us collect modern Python NumPy code solutions

#19
post #8

Earlier quoted context omitted.

The README explains that they want a single curated answer, not a list of 15 answers with 25 comments. This does seem worthwhile, at least for some types of questions.

Isn't the "curated" answer on Stack Overflow the answer with most votes? Sure, sometimes the top voted answer is not the answer to my particular problem at hand, but if it isn't, I'd rather have more alternative answers than nothing.

To a beginner they're not really able to make that determination, neither would have the patience to stay interested checking SO hundreds of times

Re: Help us collect modern Python NumPy code solutions

#20
post #6

Earlier quoted context omitted.

I looked at the C# ones - the code is not great and neither are the explanations, both show a lack of experience in C# and .NET. How to reverse the characters in a string String.Join("",("1234Simple").Select(c=>c).Reverse()); - String.Join("", - concatenate one or more characters in a single list or array, by using empty "" string literal separator - .Select(c=>c) - select each and every other character in a string i…

Indeed, their example is terrible, because it's also the kind of 'toy' problem that just doesn't have good real world uses too. How often do you want to reverse a string. I think your solution is fine and isn't "bad code" at all. Certainly a real explanation warrants talking about the IEnumerable interface. I'd also consider the simpler (and ever so slightly better performing): var buffer = "1234simple".ToArray(); Ar…

> I can't understand the use-case of needing to do this outside of toy problems.

Not sure, not my domain, but perhaps bioinformatics has the equivalent of the convolution operation on sequences?

EDIT: there is the "reversal" operation. Peeking ahead from the Rosalind problems, I'm not quite up to Reversal Distance (https://rosalind.info/problems/rear/).

Post reply on HN