I loaded a csv file into 'dataset' and tried to execute dataset.head(), but it reports an error. How to check the head or tail of a numpy array? without specifying specific lines?
NumPy's operations are divided into three main categories: Fourier Transform and Shape Manipulation, Mathematical and Logical Operations, and Linear Algebra and Random Number Generation.
For a head-like function you can just slice the array using dataset[:10]
.
For a tail-like function you can just slice the array using dataset[-10:]
.
You can do this for any python iterable.
PEP-3132 which is in python 3.x (https://www.python.org/dev/peps/pep-3132/) can use the *
symbol for the 'rest' of the iterable.
To do what you want:
>>> import numpy as np >>> np.array((1,2,3)) array([1, 2, 3]) >>> head, *tail = np.array((1,2,3)) >>> head 1 >>> tail [2, 3]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With