[SciPy-user] Concatenate without making a copy? + sandbox: models

Vincent Nijs v-nijs at kellogg.northwestern.edu
Wed Jan 3 20:22:21 CST 2007


If:

d = {'a':array([1,2,3]), 'b':array([4,3,5])}

Is is possible to do something like c_[d['a'],d['b']] in scipy without
making a copy?

The models module expects data structured in dictionaries I believe.

I am not sure I completely understand the code in the models module but I
think it creates a copy of the original data that is then processed by a
class in the module.

While the idea of using a 'data-dictionary' is very nice, this copy can be
expensive when using large data-sets. Is there a way to avoid it (i.e., a c_
like command without making a copy)?

An alternative solution that avoids copies but still allows access to data
by using variable names would be to create a single data matrix:

Array([[1,4],
       [2,3],
       [3,5]])

Store the indices in a dictionary:

d = {'a':0, 'b':1}

The data passed to the model would then be:

data[:,(d['a'],d['b'])]

The second approach can lead to a bit more book-keeping but that can easily
be wrapped in a few functions/methods. Since it uses indexing it does not
make a copy.

Is there a generally recommended/preferred approach to accessing data using
variable names?

Best,

Vincent





More information about the SciPy-user mailing list