What is the meaning of angle brackets in Python?

I found the following lines in the scikit-learn package:

if is_sparse:
    problem = csr_set_problem(
            (<np.ndarray[np.float64_t, ndim=1, mode='c']>X.data).data,
            (<np.ndarray[np.int32_t,   ndim=1, mode='c']>X.indices).shape,
            (<np.ndarray[np.int32_t,   ndim=1, mode='c']>X.indices).data,
            (<np.ndarray[np.int32_t,   ndim=1, mode='c']>X.indptr).shape,
            (<np.ndarray[np.int32_t,   ndim=1, mode='c']>X.indptr).data,
            Y.data, (<np.int32_t>X.shape[1]), bias,
            sample_weight.data)
else:
    ...

All my searches for “angle brackets in Python” provide answers to the documentation or decorator syntax , and I’m sure that this is not because it seems like real logic.

What angle brackets do in the above Python code and where I can find out more. them?

+6
source share
2 answers

This is Cython's syntax for casting / forced type. This is not simple Python. Pay attention to the file extension.pyx

Cython.

, :

cdef char *p, float *q
p = <char*>q

Cython - scikit-learn, Python C.

+6

Cython, .

, , .pyx, cimport.

+1

Source: https://habr.com/ru/post/1016172/


All Articles