You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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 array function and substitute its own to the ndarray constructor.
Hope I'm not missing anything, but it seems to me that a ndmax argument would not only solve the problem reported ("create arrays of object dtype containing equal-length sequences"), but also bring performance gains in those cases in which e.g. the last object in the input is not a list (or is a list with different length). Also see this question.
Reacted by Eric Wieser, Evan Widloski and Tobias Bergkvist
Activity
ahaldane commentedon Jul 18, 2015
I think the easiest way to get equal sized lists into an object array is in two steps:
Probable an implementation of
objectarraywould work like this.toddrjen commentedon Jul 21, 2015
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
arrayfunction and substitute its own to thendarrayconstructor.toobaz commentedon Dec 4, 2017
Hope I'm not missing anything, but it seems to me that a
ndmaxargument would not only solve the problem reported ("create arrays of object dtype containing equal-length sequences"), but also bring performance gains in those cases in which e.g. the last object in the input is not a list (or is a list with different length). Also see this question.bergkvist commentedon Jun 14, 2020
Any progress or on or plans to implement
ndmax? What I'm doing right now: