K

First, the size that shows is not what the integers of the tuplas occupy, is what they occupy the references in memory to the tuplas themselves that is what the array stores, a type array object is an array of references.NumPy numerical types as uint8 internally are not really objects (in substance of a class) as it is int in Python, they are just an 8-bit memory (byte) space that is interpreted as an integer. That is to say the concept of type is the same as in C, not the one with Python in which a type equals a class.NumPy doesn't convert anything from the tupla, your tupla is a Python object containing objects int Python and NumPy are limited to storing a reference to the tuple without further. It will never try to convert the inner objects of the object that stores, among other things, the tupla can store references to anything.A NumPy array like an array in C cannot have different rows. It is only a contiguous memory space combined with an indexed pattern that maps each item with a memory position. Therefore the concept of row/column is somewhat abstract. Basically, in the case of a 5x5 uin8 array every 8 bytes is considered a new integer and every 40 a new row or column (row-major order (C)/column-major order (FORTRAN)) but the items are stored in memory all in sequential form. If the rows or columns had variable length, the entire mapped arithmetic and pointers go to the traste and the efficiency of having the contiguous elements in memory would be lost.You can store tuplas using class numpy.uint8:(np.uint(1), np.uint(2), np.uint(3))
or use NumPy arrays directly:import numpy as np
A = np.array([], dtype=np.ndarray)
A = np.append(A, [np.array([1, 2, 3], dtype="uint8"),
np.array([4, 5], dtype="uint8"),
np.array([6, 7, 8, 9, 0], dtype="uint8")
])
print("A:", A.shape, A.nbytes, "bytes", "dtype.name:", A.dtype.name, "\n", A, "\n")
A: (3,) 24 bytes dtype.name: object[array([1, 2, 3], dtype=uint8) array([4, 5], dtype=uint8) array([6, 7, 8, 9, 0], dtype=uint8)]The array continues to occupy 24 bytes because it stores references to objects, three objects by 8 bytes each reference. No matter the object you store, a tupla other array or a list of 1000000 items, a reference in Python are 4 bytes in 32-bit Python and 8-bytes Python systems/intérprete 64-bit Python.In total you will have your array of references of 24 bytes + 3 arrays or tuplas of 3, 2 and 5 bytes each. In the case of the Python integers the length is variable since a Python integer does not always occupy the same bytes:>>> import sys
>>> sys.getsizeof(5)
28
>>> sys.getsizeof(58558724555)
32
>>> sys.getsizeof(5855875525545555548)
36
>>> sys.getsizeof(5855872455565635365566956333336356699353355365886653553533556886855355565698869)
60
Another more bizarre option is to use a https://docs.python.org/3/library/array.html Python with type "b" or "B" instead of tuples.