[Python] How to pretty-print a tuple of NumPy scalars?

Discussão em 'Python' iniciado por Stack, Setembro 1, 2025.

  1. Stack

    Stack Membro Participativo

    This script:

    import numpy as np

    a = np.arange(24).reshape(2, 2, 2, 3)
    idx = np.unravel_index(np.argmax(a, axis=None), a.shape)
    print(idx)


    will print:

    (np.int64(1), np.int64(1), np.int64(1), np.int64(2))


    which is hard to read. What is a simple way to print idx as (1, 1, 1, 2)? I'm looking for something better than print(np.array(idx)) workaround.

    Continue reading...

Compartilhe esta Página