MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / list_to_1d_numpy

Function list_to_1d_numpy

python-package/lightgbmmt/basic.py:69–89  ·  view source on GitHub ↗

Convert data to numpy 1-D array.

(data, dtype=np.float32, name='list')

Source from the content-addressed store, hash-verified

67
68
69def list_to_1d_numpy(data, dtype=np.float32, name='list'):
70 """Convert data to numpy 1-D array."""
71 if is_numpy_1d_array(data):
72 if data.dtype == dtype:
73 return data
74 else:
75 return data.astype(dtype=dtype, copy=False)
76 elif is_1d_list(data):
77 return np.array(data, dtype=dtype, copy=False)
78 elif isinstance(data, Series):
79 if _get_bad_pandas_dtypes([data.dtypes]):
80 raise ValueError('Series.dtypes must be int, float or bool')
81 return np.array(data, dtype=dtype, copy=False) # SparseArray should be supported as well
82 elif isinstance(data, np.ndarray) and data.shape[1] > 1:
83 if data.dtype == dtype:
84 return data.transpose().reshape(-1)
85 else:
86 return data.transpose().astype(dtype=dtype, copy=False).reshape(-1)
87 else:
88 raise TypeError("Wrong type({0}) for {1}.\n"
89 "It should be list, numpy 1-D array or pandas Series".format(type(data).__name__, name))
90
91
92def cfloat32_array_to_numpy(cptr, length):

Callers 7

constructMethod · 0.85
set_fieldMethod · 0.85
set_labelMethod · 0.85
set_weightMethod · 0.85
set_init_scoreMethod · 0.85
set_groupMethod · 0.85
__boostMethod · 0.85

Calls 6

is_numpy_1d_arrayFunction · 0.85
is_1d_listFunction · 0.85
_get_bad_pandas_dtypesFunction · 0.85
typeEnum · 0.85
arrayMethod · 0.80
formatMethod · 0.80

Tested by

no test coverage detected