numpy.ndarray show first in python

You can use the numpy.ndarray to show the first few elements of an array in Python by slicing the array with the indexes of the elements you want to display.

Here's an example of how to show the first 5 elements of a numpy array:

main.py
import numpy as np

# Create a numpy array
arr = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9])

# Display the first 5 elements
print(arr[:5])
134 chars
8 lines

This will output:

main.py
[1 2 3 4 5]
12 chars
2 lines

related categories

gistlibby LogSnag