argsort一个PyTables“阵列 [英] argsort on a PyTables' array
问题描述
我有numpy的的argsort一个问题。它会在内存中的输入数组的长度的一个Int64数组。由于我具有非常大的阵列工作,这将打击的记忆。
I have a problem with NumPy's argsort. It creates an int64 array of the length of the input array in-memory. Since I'm working with very large arrays, this will blow the memory.
我测试numpy的与小PyTablesCARRAY argsort并给出了正确的输出。现在,我要的是一个PyTables阵列直接排序算法的工作。有没有办法与标准的numpy的做到这一点调用或简单的黑客进入numpy的内部?
I tested NumPy's argsort with a small PyTables' carray and it gives the correct output. Now, what I want is to the sorting algorithm work with a PyTables' array directly. Is there a way to do this with standard NumPy calls or a simple hack into the NumPy internals?
我也开放给非numpy的替代品 - 我只想把工作做好
I'm also open to non-NumPy alternatives - I just want to get the job done!
推荐答案
由于您使用Pytables工作,我建议你使用已经内置排序表中的类。
Since you are working with Pytables, I suggest you use the Table class which has sorting built in.
%pylab
import tables
#create description of your table
class Table_Description(tables.IsDescription):
column_name = tables.Int64Col()
#create hdf5 file and table
f=tables.open_file('test.h5',mode="w")
a=f.create_table("/","my_table",description=Table_Description)
# fill table
a.append(array([randint(0,99999) for i in xrange(10000)]))
#Create a full index (on disk if you use the tmp_dir parameter
a.cols.column_name.create_index(9,kind='full',tmp_dir="/tmp/")
#write changes to disc
a.flush()
#read indices that will sort the table
ind=f.root.my_table.cols.column_name.index
ind.read_indices()
这篇关于argsort一个PyTables“阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!