23 Aug
2021
23 Aug
'21
11:15 p.m.
Steven D'Aprano wrote:
I don't think it is very common to use numpy arrays in a context where they are expected to duck-type as collections.
Maybe not "numpy arrays duck-type as collections", but it is very common that arrays and sequences are used interchangably. Numpy has created the term "array-like" for this. Well technically, an array-like is something that `np.array()` can turn into an array. But from a user point of view array-like effectively means array or sequence. If you want to write a function that accepts array-like `values`, you have to change a check `if values` to `if len(values) == 0`. That works for both but is against the PEP8 recommendation. This is a shortcoming of the language.