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
Enh: Object array creation function #5933
Comments
I think the easiest way to get equal sized lists into an object array is in two steps:
Probable an implementation of |
Yes, that is currently the best way, but it is needlessly verbose. Hence this idea. I would hope that an implementation of this idea would simply be able to bypass the automatic conversion used in the |
Hope I'm not missing anything, but it seems to me that a |
Any progress or on or plans to implement np.array([*data, None])[:-1]
# This would look a lot cleaner:
np.array(data, ndmax=1) |
As discussed in issue #5303, currently it is not possible to create arrays of object dtype containing equal-length sequences, since the sequence is automatically read in as array elements. There is a suggestion to only do this for lists, but this would be a major backwards compatibility break and would require a long deprecation period.
Another approach would be to have a function explicitly for creating arrays with an object dtype. Perhaps this could be called "objectarray". The default for this function would be to take in a sequence, and consider each element of the sequence as an element in a 1D object array.
The function, however, could have an optional "ndim" or "depth" argument, that could be used to specify how many levels of the sequence should be considered part of the array. This would default to 0 (only the outermost level is considered). This would raise an exception if the dimensions don't match.
Note that this approach is not mutually exclusive with the alternative, but has the advantage that it wouldn't break backwards-compatibility.
So for example:
The text was updated successfully, but these errors were encountered: