-
Notifications
You must be signed in to change notification settings - Fork 53
Adding support for len
/__len__
#481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It's hard to search for because "len" isn't a very unique string, but we discussed this multiple times for both arrays and dataframes and there was wide agreement that @jakirkham I propose we close this. |
Interesting maybe I'm missing context here Thought the main issue was dimensions of unknown length. This was noted when it was originally included and then removed ( #289 ) Anyways am wondering if we should revisit given the number of lines of code using |
The reason is that there is an alternative way to look at arrays; which is also the one that SymPy uses (for its matrix):
By not specifying Starting from scratch, I would personally consider that choice. Because I like to think of arrays more as a "collection of values/elements with a homogenous structure". The "collection of values/elements" comes first and the "structure" only later in my philosophy :). That does break the list-of-lists analogy which may be confusing to users. But to some degree that is a feature not a bug. |
Yes, I think that is more reasonable indeed.
Honestly, I think this is (a) not a hard thing to change all at once for a code base, and (b) a good improvement for readability even in the absence of array API usage. |
One semi-related thing I would actually like to add to NumPy - but never worked on - is And otherwise axis selecting all axes to be iterate. |
I agree that arrays don't need to be directly iterable & with a length, but we do need a way to unpack arrays along an axis into a list. If we don't have any way to do that currently in the standard, then we need an |
Can you clarify why this is needed? Typically if you want to work along an axis of an array you just work along that axis. This can be done with a list comprehension: |
OK, fair enough, indexing in a loop would definitely do the trick here. Still maybe worth considering adding |
Can we close this issue with outcome that the proposal is rejected? No requirement to add |
No more comments, I'll close this. Thanks all! |
Several array implementation currently implement
len
/__len__
basically as shorthand for.shape[0]
. It would be handy to have this to simplify adoption in existing codes as well as fit more with how current array implementations workThe text was updated successfully, but these errors were encountered: