Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A colon before a number in numpy array

I'm using a camera to store raw data in a numpy array, but I don't know What does mean a colon before a number in numpy array?

import numpy as np
import picamera

camera = picamera.PiCamera()
camera.resolution = (128, 112)
data = np.empty((128, 112, 3), dtype=np.uint8)
camera.capture(data, 'rgb')
data = data[:128, :112]
like image 327
biomedical spartan Avatar asked Jul 26 '26 21:07

biomedical spartan


1 Answers

numpy array indexing is explained in the doc.

this example shows what is selected:

import numpy as np

data = np.arange(64).reshape(8, 8)
print(data)
data = data[:3, :5]
print(data)

the result will be the first 5 elements of the first 3 rows of the array.

as in standard python lst[:3] means everything up to the third element (i.e. the element with index < 3). in numpy you can do the same for every dimension with the syntax given in your question.

like image 104
hiro protagonist Avatar answered Jul 30 '26 08:07

hiro protagonist



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!