File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 31
31
32
32
33
33
def _ensure_float (arr ):
34
+ """
35
+ Ensure that an array object has a float dtype if possible.
36
+
37
+ Parameters
38
+ ----------
39
+ arr : The array whose data type we want to enforce as float.
40
+
41
+ Returns
42
+ -------
43
+ float_arr : The original array cast to the float dtype if
44
+ possible. Otherwise, the original array is returned.
45
+
46
+ Examples
47
+ --------
48
+ >>> arr = np.array([1, 2, 3], dtype=np.int64)
49
+ >>> arr
50
+ array([1, 2, 3])
51
+ >>>
52
+ >>> arr.dtype
53
+ dtype('int64')
54
+ >>>
55
+ >>> float_arr = _ensure_float(arr)
56
+ >>> float_arr
57
+ array([ 1., 2., 3.])
58
+ >>>
59
+ >>> float_arr.dtype
60
+ dtype('float64')
61
+ """
62
+
34
63
if issubclass (arr .dtype .type , (np .integer , np .bool_ )):
35
64
arr = arr .astype (float )
36
65
return arr
You can’t perform that action at this time.
0 commit comments