A Divendres 26 Maig 2006 20:55, Pepe Barbe va escriure:
> Hi,
>
> Something I recently noticed in my code and I don't know if it's a
> mistake from my part or something that comes from PyTables.
>
> I have some code that goes like this:
> from numpy import *
> from tables import *
>
> some_array = zeros(len)
> some_list = list()
>
> <populate some_array and some_list>
>
> SomeTable = { 'Some':FloatCol( shape=shape(some_array) )}
> table = h5_db.createTable( 'somewhere','SomeTable', SomeTable,'SomeTable
> Desc' )
>
> row = table.row
> row['Some'] = some_array
> row.append()
> table.flush()
>
> My problem is that when I retrieve the information from the table I've
> noticed that array in the Table has the following shape (1,len) while
> the VLArray has (len,). While both look like one dimensional arrays,
> they are actually different in numpy and therefore complicate things a
> bit. I've checked the output of shape(some_array) and it is (len,); so
> I am assuming, that PyTables is doing this change.
>
> I'd like to know if I am write or wrong about this, if this is a
> feature or a bug in PyTables and how to possibly avoid it, since I am
> interested in storing and retrieving the exact same array that I store
> in my DB.
Mmm, this doesn't seem a bug to me. Look at the next small program so that you
can check how to access Tables in order to get consistent shapes:
---------------------------------------------------------------------------
from numpy import *
from tables import *
len = 10
some_array = ones(len, dtype="float64")
print "input array type -->", type(some_array)
print "input array values -->", some_array
h5_db = openFile("prova.h5","w")
SomeTable = { '_v_flavor': 'numpy', 'Some':FloatCol(shape=shape(some_array))}
table = h5_db.createTable('/','SomeTable', SomeTable, 'SomeTable Desc')
row = table.row
row['Some'] = some_array
row.append()
table.flush()
aout = table.cols.Some[0]
print "output array type -->", type(aout)
print "output array values -->", aout
h5_db.close()
--------------------------------------------------------
The output for my case is:
------------------------------------------------------------------------------
input array type --> <type 'numpy.ndarray'>
input array values --> [ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
output array type --> <type 'numpy.ndarray'>
output array values --> [ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
------------------------------------------------------------------------------
Using PyTables 1.3.1 and Linux here.
Regards,
--
>0,0< Francesc Altet http://www.carabos.com/
V V Cárabos Coop. V. Enjoy Data
"-"
-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid7521&bid$8729&dat1642
_______________________________________________
Pytables-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pytables-users