print ndarray as simple int in python

You can print a NumPy ndarray as a simple int in Python by converting it to a Python list first and then printing it. Here's how you can do it:

main.py
import numpy as np

# Create a NumPy ndarray
arr = np.array([1, 2, 3, 4])

# Convert the NumPy ndarray to a Python list
arr_list = arr.tolist()

# Print the list as a simple int
print(*arr_list)
195 chars
11 lines

This will output:

main.py
1 2 3 4
8 chars
2 lines

related categories

gistlibby LogSnag