diff --git a/python-package/xgboost/core.py b/python-package/xgboost/core.py index 66d470648..8acd3ef89 100644 --- a/python-package/xgboost/core.py +++ b/python-package/xgboost/core.py @@ -159,6 +159,8 @@ def c_str(string): def c_array(ctype, values): """Convert a python string to c array.""" + if isinstance(values, np.ndarray) and values.dtype.itemsize == ctypes.sizeof(ctype): + return (ctype * len(values)).from_buffer_copy(values) return (ctype * len(values))(*values)