astype
Copies an array to a specified data type irrespective of type-promotion rules.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
array to cast. |
required | |
dtype
|
desired data type. |
required | |
copy
|
specifies whether to copy an array when the specified |
True
|
Notes
-
When casting a boolean input array to a real-valued data type, a value of
True
is cast to a real-valued number equal to1
, and a value ofFalse
must cast to a real-valued number equal to0
. -
When casting a boolean input array to a complex floating-point data type, a value of
True
is cast to a complex number equal to1 + 0j
, and a value ofFalse
is cast to a complex number equal to0 + 0j
. -
When casting a real-valued input array to
bool
, a value of0
is cast toFalse
, and a non-zero value is cast toTrue
. -
When casting a complex floating-point array to
bool
, a value of0 + 0j
is cast toFalse
, and all other values are cast toTrue
.
Returns:
Name | Type | Description |
---|---|---|
out |
array
|
an array having the specified data type. The returned array has the same shape as |
Examples:
>>> a = sparse.COO.from_numpy(np.array([[0, 1], [2, 0]]))
>>> o = sparse.astype(a, "float32")
>>> o.todense()
array([[0., 1.],
[2., 0.]], dtype=float32)
Source code in sparse/numba_backend/_common.py
2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 |
|