The short answer is no. Although the syntax for numpy arrays looks the same as the standard python syntax, what happens behind the scenes is very different. Complex numpy data types, such as TA , use large blocks of contiguous memory to store each record; the memory must be laid out regularly, or everything falls apart.
Therefore, when you create an array of 1000 elements with a nested data type, such as TA , you actually allocate 1000 memory blocks, each of which is large enough to contain N distinct TB arrays. That is why you can do things like a['B']['D'] - or to indicate a point on it, for example:
>>> (a['B'][1]['D'] == a['B']['D'][1]).all() True >>> a['B'][1]['D'][0] = 123456789 >>> (a['B'][1]['D'] == a['B']['D'][1]).all() True
For regular Python objects, the above will not be done, since the order of access to the object matters. It is actually very strange that this is possible in numpy , and the only reason this is possible is because numpy uses uniformly structured continuous memory.
As far as I know, numpy provides no way to do what you ask (someone correct me if I'm wrong!), And the required numbering will probably require significant changes to the numpy API.
I will add that I do not think it makes sense to do this anyway. If only one copy of the array is required, why not just store it outside the array? You can even pass it along with a numpy array, as part of tuple or namedtuple .
source share