I ended up defining an alias:
Float = Union[float, numpy.float64]
but I wonder if there is a more legitimate way to handle thiss.
31–40 of 41 posts
I ended up defining an alias:
Float = Union[float, numpy.float64]
but I wonder if there is a more legitimate way to handle thiss.
Earlier quoted context omitted.
Fixed some of those. Simple case of just pushing the edit button and sending a PR.
The suggested solution https://github.com/Onelinerhub/onelinerhub/blob/34467e427cc6... still runs out of memory with many files. I believe the original intention behind using mode="a" was to append to the output file while reading the input files at the same time. This way, there is no need for an ever-growing string array. But there are still many other issues like using default platform string encoding instead of d…
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…
%: +/ *: x
Is impossible to read of course without learning the J language's main constructs. While the python function application is easier to guess from other languages.Earlier quoted context omitted.
>>> 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.
If there was an example using just `np.c_[1:5, 11:15]` it would make sense. But clearly np.c_'s meaning has been extended beyond slices in some way. (Maybe I'm coming closer to understanding, but still miffed about the misleading doc.)
Earlier quoted context omitted.
That does not zip though. In fact, it creates a 1-dimensional array of objects because the arrays do not have the same number of items. >>> a = [np.arange(i) for i in range(1, 11)] >>> np.array(a).T array([array([0]), array([0, 1]), array([0, 1, 2]), array([0, 1, 2, 3]), array([0, 1, 2, 3, 4]), array([0, 1, 2, 3, 4, 5]), array([0, 1, 2, 3, 4, 5, 6]), array([0, 1, 2, 3, 4, 5, 6, 7]), array([0, 1, 2, 3, 4, 5, 6, 7, 8])…
You are completely right. Nevertheless, when I zip over arrays of different length, it is usually a bug instead of being intentional. A code-golfed version for different array lengths: np.c_[[a[:min(map(len,arrays))].T for a in arrays]].T The trick to get a local variable within a list comprehension statement with for l in [foo()] from your zip_array function is very cool by the way, but I sacrificed it in favor of s…
I am glad you liked the trick!
Why do so few libraries seem to understand that good documentation starts by providing meaningful examples of simple tasks with semantic labels that can be found via search? Reference-style documentation assumes that you already know the name of the thing you're looking for (you don't), or that you have time to read for several days and build up an entire mental model of the system in one go before getting anything productive done (also no).
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…
Interesting suggestion since %: +/ *: x Is impossible to read of course without learning the J language's main constructs. While the python function application is easier to guess from other languages.
I would love to see something like this for `pandas`. Also SQLAlchemy. EDIT: apparently there's a very limited set of oneliners for `pandas` already. Why do so few libraries seem to understand that good documentation starts by providing meaningful examples of simple tasks with semantic labels that can be found via search? Reference-style documentation assumes that you already know the name of the thing you're looking…
Earlier quoted context omitted.
Interesting suggestion since %: +/ *: x Is impossible to read of course without learning the J language's main constructs. While the python function application is easier to guess from other languages.
I know English, so I'll just guess at what those non-English people are saying. What could go wrong?
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?