If I have a dtype like
foo = dtype([('chrom1', '<f4', (100,)), ('chrom2', '<f4', (13,))])
How can I create an instance of that dtype, as a scalar.
Background, in case There's A Better Way:
I want to efficiently represent arrays of scalars mapping directly to the bases in a genome, chromosome by chromosome. I don't want arrays of these genomic arrays, each one is simply a structured set of scalars that I want to reference by name/position, and be able to add/subtract/etc.
It appears that dtype.type() is maybe the path forward, but I haven't found useful documentation for correctly calling this function yet.
So suppose I have:
chrom1_array = numpy.arange(100)
chrom2_array = numpy.arange(13)
genomic_array = foo.type([chrom1_array, chrom2_array])
That last line isn't right, but hopefully it conveys what I'm currently attempting.
Is this a horrible idea? If so, what's the right idea? If not, what's the correct way to implement it?
This sort of works, but is terrible:
bar = np.zeros(1, dtype=[('chrom1', 'f4', 100), ('chrom2', 'f4', 13)])[0]
try this:
foo = np.dtype([('chrom1', '<f4', (100,)), ('chrom2', '<f4', (13,))])
t = np.zeros((), dtype=foo)