I've seen np.int0
used for converting bounding box floating point values to int in OpenCV problems.
What exactly is np.int0
?
I've seen np.uint8
, np.int32
, etc. I can't seem to find np.int0
in any online documentation. What kind of int does this cast arguments to?
NumPy performs operations element-by-element, so multiplying 2D arrays with * is not a matrix multiplication – it's an element-by-element multiplication.
NumPy dtypeA data type object implements the fixed size of memory corresponding to an array. We can create a dtype object by using the following syntax. The constructor accepts the following object. Object: It represents the object which is to be converted to the data type.
NumPy data types uint8 In Python uint8 datatype indicates unsigned integer and it consists of 8 bits with positive range values from 0 to 255. This datatype store information about the type byte order and bit-width with 'C'unsigned character.
A numpy array is a grid of values, all of the same type, and is indexed by a tuple of nonnegative integers. The number of dimensions is the rank of the array; the shape of an array is a tuple of integers giving the size of the array along each dimension.
int0
is an alias for intp
; this, in turn, is
Integer used for indexing (same as C ssize_t; normally either
int32
orint64
)
-- Numpy docs: basic types
It's a mere alias to int64
, try this from either Python 2 or Python 3:
>>> import numpy
>>> numpy.int0 is numpy.int64
True
Here is some more information:
# get complete list of datatype names
>>> np.sctypeDict.keys()
# returns the default integer type (here `int64`)
>>> np.sctypeDict['int0']
<class 'numpy.int64'>
# verify
>>> arr = np.int0([1, 2, 3])
>>> arr.nbytes
24
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