Input validation on an array, list, sparse matrix or similar. By default, the input is checked to be a non-empty 2D array containing only finite values. If the dtype of the array is object, attempt converting to float, raising on failure. Parameters ---------- array : objec
(
array,
accept_sparse=False,
*,
accept_large_sparse=True,
dtype="numeric",
order=None,
copy=False,
force_writeable=False,
ensure_all_finite=True,
ensure_non_negative=False,
ensure_2d=True,
allow_nd=False,
ensure_min_samples=1,
ensure_min_features=1,
estimator=None,
input_name="",
)
| 731 | |
| 732 | |
| 733 | def check_array( |
| 734 | array, |
| 735 | accept_sparse=False, |
| 736 | *, |
| 737 | accept_large_sparse=True, |
| 738 | dtype="numeric", |
| 739 | order=None, |
| 740 | copy=False, |
| 741 | force_writeable=False, |
| 742 | ensure_all_finite=True, |
| 743 | ensure_non_negative=False, |
| 744 | ensure_2d=True, |
| 745 | allow_nd=False, |
| 746 | ensure_min_samples=1, |
| 747 | ensure_min_features=1, |
| 748 | estimator=None, |
| 749 | input_name="", |
| 750 | ): |
| 751 | """Input validation on an array, list, sparse matrix or similar. |
| 752 | |
| 753 | By default, the input is checked to be a non-empty 2D array containing |
| 754 | only finite values. If the dtype of the array is object, attempt |
| 755 | converting to float, raising on failure. |
| 756 | |
| 757 | Parameters |
| 758 | ---------- |
| 759 | array : object |
| 760 | Input object to check / convert. |
| 761 | |
| 762 | accept_sparse : str, bool or list/tuple of str, default=False |
| 763 | String[s] representing allowed sparse matrix formats, such as 'csc', |
| 764 | 'csr', etc. If the input is sparse but not in the allowed format, |
| 765 | it will be converted to the first listed format. True allows the input |
| 766 | to be any format. False means that a sparse matrix input will |
| 767 | raise an error. |
| 768 | |
| 769 | accept_large_sparse : bool, default=True |
| 770 | If a CSR, CSC, COO or BSR sparse matrix is supplied and accepted by |
| 771 | accept_sparse, accept_large_sparse=False will cause it to be accepted |
| 772 | only if its indices are stored with a 32-bit dtype. |
| 773 | |
| 774 | .. versionadded:: 0.20 |
| 775 | |
| 776 | dtype : 'numeric', type, list of type or None, default='numeric' |
| 777 | Data type of result. If None, the dtype of the input is preserved. |
| 778 | If "numeric", dtype is preserved unless array.dtype is object. |
| 779 | If dtype is a list of types, conversion on the first type is only |
| 780 | performed if the dtype of the input is not in the list. |
| 781 | |
| 782 | order : {'F', 'C'} or None, default=None |
| 783 | Whether an array will be forced to be fortran or c-style. |
| 784 | When order is None (default), then if copy=False, nothing is ensured |
| 785 | about the memory layout of the output array; otherwise (copy=True) |
| 786 | the memory layout of the returned array is kept as close as possible |
| 787 | to the original array. |
| 788 | |
| 789 | copy : bool, default=False |
| 790 | Whether a forced copy will be triggered. If copy=False, a copy might |
searching dependent graphs…