Convert data to numpy 1-D array.
(data, dtype=np.float32, name='list')
| 67 | |
| 68 | |
| 69 | def 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 | |
| 92 | def cfloat32_array_to_numpy(cptr, length): |
no test coverage detected