12 ms·
I like to stop and appreciate the ndarray abstraction. It's a really beautiful interface that hits all the right spots to me. Anytime I'm working with numerical
by fouronnes3 6y ago
I like to stop and appreciate the ndarray abstraction. It's a really beautiful interface that hits all the right spots to me. Anytime I'm working with numerical data in a language without an ndarray I miss it quite strongly. Indexing, slices, broadcasting... it's all so brilliant.
- sleavey 6y agoAgreed. I occasionally imagine a feature that it would be cool to have in Numpy, then find that it's already there. Most recently I discovered (somewhat lately) that you can create arbitrarily structured arrays and store things like strings alongside array elements [1]. [1] https://numpy.org/doc/stable/user/basics.rec.html https://numpy.org/doc/stable/user/basics.rec.html
- enriquto 6y agoAs a counterpoint, if you are used to real, language-supported numerical arrays, then numpy's ndarray seems like a joke.
- emmelaich 6y agoelaborate please
- Jenz 6y agoThis must have piqued a number of readers interedts, mine included. Are you reffering to something like Matlab? Julia?
- enriquto 6y agoThere's many programming languages where multidimensional arrays of floats are a natural language construct. From low-level (e.g. Fortran) to high level languages (e.g. Octave/Matlab, Julia). Even in C you can work with multidimensional arrays of floats, but it is a bit cumbersome. This is not the case for Python, where the language cannot express in itself this data structure, and it needs external library support like numpy. EDIT: I'm always very surprised by the wide acceptance of python/numpy for numerical algorithms, as it seems a notion quite foreign and awkward for this language. Python has excellent native support for string processing and advanced data structures like dictionaries, but those are mostly useless for numerical computation. If you want to do math in Python, you need to write libraries in other languages and provide a Phython interface. This is what scipy does, and it is a very good job, but it does not feel "natural" from the point of view of the language. If Python was a good scientific programming language, the most natural way to implement scipy/numpy and all that would be using Python itself, but this is not at all the case.
- pletnes 6y agoI think numpy is mostly great. Although I do agree - numpy should be in the stdlib, period. So many users come from the scientific/data/simulation communities. It’s just that there are no (or too few) core devs from that tradition. Python lacking numpy in the base language is as awful as Fortran lacking dict-like data structures in its runtime.
- enriquto 6y ago> numpy should be in the stdlib, period. I disagree strongly with this. Numerical facilities should not be in the stdlib, they should be in the language itself, without need to "import" anything. I can create strings and dictionaries without any imports. I should be able to create a multidimensional array of floats, and perform natural operations with it (like matrix multiplication) without importing anything. As per the dictionaries in Fortran, there are libraries for that. But I think that not having complex data structures in Fortran is a feature, not a bug. If you actually need these data structures, many Fortran programmers will tell you to just use a different language. You'll never hear such a plainly honest answer from Python programmers; they'll tell you instead to use bizarre libraries with unnatural interfaces, and you'll be forced to multiply matrices using a function "numpy.dot" or an ugly operator "@".
- fishmaster 6y agoThis is exactly why I'm going to Julia. It either has these constructs in the language itself or is powerful enough to express them adequately. Numpy is a necessary crutch for Python.
- pc86 6y agoYou're going to Julia so that you can avoid typing "import numpy as np" at the beginning of a file? Or is there more to it?
- fishmaster 6y ago
- deleted 6y ago[deleted]
- nxpnsv 6y agoI really don’t care if np is not part of python dist. Install is trivial and It does what it does really well and is very usable.