All arrays have metadata. You can set it like so (f is a pytables file):

annotated = f.createArray('/', 'annotated', [1,2,3])
annotated.attrs.name = 'Spam'
annotated.attrs.really = True
annotated.attrs.frac = 0.123

Again, not as fast / indexed as a table, but if you're loading it all into memory, who cares?

You need to be a little careful reading the attrs off... PyTables also keeps some stuff in there (which I'm guessing you don't want!). The user attribute names are in attrs._v_attrnamesuser if your program doesn't know what to expect ahead of time.

Cheers,
DC

On May 21, 2009, at 7:35 PM, Robert Ferrell wrote:

Thanks for the input. This is exactly what I ended up doing. Works fine. Seems like a very common use case for (novice?) scipy users. I wonder if it would be helpful to have this use case / example highlighted someplace. (Perhaps it is and I just missed it. I looked around quite a bit, though.)

Do you know if it is possible to attach attributes to the array? I have just a few other scalars that I'd love to bundle up it.

-robert

On May 21, 2009, at 6:21 PM, Dav Clark wrote:

I feel like this is the same (only?) message I always send to people on the list...

Have you considered simply storing each item as a separate atomic array? Then you don't need to mess with any of this VLArray stuff, or tables at all. I know it's called PyTables, but you can actually get a lot done simply with named arrays (still get compression, some cacheing and so forth).

Sure, it may be slower than a table, but you can get it done. Here's an example of what I mean:

for i in range(10000):
f.createArray('/', 'array%d' % i, np.random.random(np.random.random_integers(10)))

That takes a fair few seconds, but you can always make it faster later... Two separate "tables" is currently the only way to deal with variable length arrays in a Tabley way. Or, you can pad all arrays to the same length.

Cheers,
Dav

On May 21, 2009, at 4:08 PM, Robert Ferrell wrote:

Okay, I'm completely confused.  I've gone through the docs and there
are many examples, but I can't find anything as simple as I want.
Maybe I'm not using the right tool?

In it's simplest form, I have a large number of (name, np array)
tuples.  (I happen to store them in a dict, and the np arrays are
actually TimeSeries instances, but I don't think that's important for
my very basic lack of understanding.)

I'd like to write a table with 2 columns, the first is a string (for
the name) the second is an np array (for the data).  How do I do
that?  I was expecting something like:

class SimpTab(tb.IsDescription):
        name = tb.StringCol(itemsize=10)
        dta = *something that says this is a numpy array*

I've found the createArray method, but I don't think that does what I
want.  I thought there'd be some NpArrayCol() type thing.

I don't need to do any fancy selection, I just need to dump the data
to disk and then read it back in.  The whole data set is only about
1GB, so it's no problem reading the whole thing into memory.  Am I
using the wrong tool?

Sorry to be so dense.

thanks,
-robert

------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet the minds behind Google Creative Lab, Visual Complexity, Processing, & iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users

------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet the minds behind Google Creative Lab, Visual Complexity, Processing, & iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian Group, R/GA, & Big Spaceship. http://www.creativitycat.com _______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users


------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com 
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to