[Python] Size of data type using NumPy

Discussão em 'Python' iniciado por Stack, Agosto 28, 2025.

  1. Stack

    Stack Membro Participativo

    In NumPy, I can get the size (in bytes) of a particular data type by:

    datatype(...).itemsize


    or:

    datatype(...).nbytes


    For example:

    np.float32(5).itemsize # 4
    np.float32(5).nbytes # 4


    I have two questions. First, is there a way to get this information without creating an instance of the datatype? Second, what's the difference between itemsize and nbytes?

    Continue reading...

Compartilhe esta Página