[Numpy-discussion] recarrays and lists of lists
Sun Sep 11 14:56:52 CDT 2011
On Sun, Sep 11, 2011 at 14:44, Travis Vaught <email@example.com> wrote:
> On Sep 11, 2011, at 2:58 AM, Robert Kern wrote:
>> On Sun, Sep 11, 2011 at 00:30, Travis Vaught <firstname.lastname@example.org> wrote:
>>> Is there a particular reason why a list of lists can't be passed in to create a recarray given a particular dtype?
>>> A list of tuples works fine. I keep getting bitten by this and was thinking it should be an easy check/convert for an allowance for a row to be a list _or_ a tuple?
>> As a rule, tuples are considered "scalar" records and lists are
>> recursed upon. This rule helps numpy.array() figure out which
>> sequences are records and which are other sequences to be recursed
>> upon; i.e. which sequences create another dimension and which are the
>> atomic elements. Otherwise, it has to make some guesses and do some
>> intelligent backtracking. It's not that intelligent.
>> Robert Kern
> Thanks for the explanation. It makes a bit of sense -- at least to answer the question of what is being traded off here. Looks like simplicity and performance, perhaps, is being chosen over my convenience.
Mostly unambiguity. numpy.array() has to figure out several
interrelated things simultaneously, so there is an identifiability
problem. Too many equations, not enough data points; the tuple/list
distinction provides an additional data point that helps numpy.array()
do what it needs to do.
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
More information about the NumPy-Discussion