Live data from Hacker News

NumPy 2.0

numpy.org

71–78 of 78 posts

Re: NumPy 2.0

#71
post #70
post #59

Earlier quoted context omitted.

Most of the bugs I got on numpy programs came from a variable with a different ndims as expected being broadcast implicitly. Implicit type casting is considered a mistake in most programming languages; if I were to redesign numpy from scratch I would make all broadcasting explicit. My solution to these problems is asserting an array's shape often. Does anybody know is there's a tool like mypy or valgrind, but that ch…

numpy's API was carefully designed to match matlab, where most of its early users came from.

Then we are lucky they didn't decide to start their arrays at 1 :-)

Re: NumPy 2.0

#72
post #25
post #16

The thing I want most is a more sane and more memorable way to compose non-element-wise operations. There are so many different ways to build views and multiply arrays that I can’t remember them and never know which to use, and have to relearn them every time I use numpy… broadcasting, padding, repeating, slicing, stacking, transposing, outers, inners, dots of all sorts, and half the stack overflow answers lead to th…

When I started out I was basically stumbling around for code that worked. Things got a lot easier for me once I sat down and actually understood broadcasting. The rules are: 1) scalars always broadcast, 2) if one vector has fewer dimensions, left pad it with 1s and 3) starting from the right, check dimension compatibility, where compatibility means the dimensions are equal or one of them is 1. Example: np.ones((2,3,1…

This is also helpful: https://github.com/srush/Tensor-Puzzles

Re: NumPy 2.0

#73

I would love for numpy to be ported as a typescript project personally. So I can do ml in ts. The python ecosystem feels a bit insane to me (more so than the js one). Venv helps but is still inferior to a half decent npm project imo. I feel there is no strict reason why this migration couldn't happen, only the inertia that makes it unlikely

I think it is "better" to go with the flow. I can't see TS competing for the data analysis niche any time soon!

Maybe try Pixi? [1] Python programming enjoyability really increased for me after using Pixi for dependencies, VSCode+Pylance [2] for editing, and Ruff [3] for formatting.

Pixi can install both python and dependencies _per project_. Then, I add this to .vscode/settings.json:

    {
      "python.analysis.typeCheckingMode": "strict", 
      "python.defaultInterpreterPath": ".pixi/envs/default/bin/python3"
    }
and I'm all set!

--

1: https://pixi.sh

2: https://github.com/microsoft/pylance-release#readme

3: https://docs.astral.sh/ruff/

Re: NumPy 2.0

#74
post #71
post #70

Earlier quoted context omitted.

numpy's API was carefully designed to match matlab, where most of its early users came from.

Then we are lucky they didn't decide to start their arrays at 1 :-)

indeed...

Re: NumPy 2.0

#75
post #25

Earlier quoted context omitted.

When I started out I was basically stumbling around for code that worked. Things got a lot easier for me once I sat down and actually understood broadcasting. The rules are: 1) scalars always broadcast, 2) if one vector has fewer dimensions, left pad it with 1s and 3) starting from the right, check dimension compatibility, where compatibility means the dimensions are equal or one of them is 1. Example: np.ones((2,3,1…

The broadcasting doc is surprisingly readable and easy to follow. And the rules are surprisingly simple. The diagrams and examples are excellent. https://numpy.org/doc/stable/user/basics.broadcasting.html After taking the time to work through that doc and ponder some real-world examples, I went from being very confused by broadcasting to employing intermediate broadcasting techniques in a matter of weeks. Writing out…

Please please don't put that in your head or your notepad. This is what code comments are for!

Re: NumPy 2.0

#77
post #75

Earlier quoted context omitted.

The broadcasting doc is surprisingly readable and easy to follow. And the rules are surprisingly simple. The diagrams and examples are excellent. https://numpy.org/doc/stable/user/basics.broadcasting.html After taking the time to work through that doc and ponder some real-world examples, I went from being very confused by broadcasting to employing intermediate broadcasting techniques in a matter of weeks. Writing out…

Please please don't put that in your head or your notepad. This is what code comments are for!

You definitely should "annotate" arrays with their expected sizes, but if you're doing a lot of broadcasting operations it can get pretty verbose to write out those tables over and over.

That said, yes, you definitely should at least make an attempt to clarify your broadcasting logic if you want to be able to read your own scripts in a month from now, let alone write maintainable production code.

Post reply on HN