num_samples#
- pybear.base.num_samples(X)#
Return the number of samples in an array-like X.
X must have a ‘shape’ attribute.
- numpy, pandas, & polars:
X must be 1 or 2 dimensional.
- scipy:
X must be 2 dimensional.
If X is a 1D vector (i.e., len(X.shape)==1), return len(X).
- Parameters:
- XXContainer of shape (n_samples, n_features) or (n_samples,)
Object to find the number of samples in, that has a ‘shape’ attribute.
- Returns:
- rowsint
Number of samples.
Notes
Type Aliases
- NumpyTypes:
numpy.ndarray
- PandasTypes:
pandas.Series | pandas.DataFrame
- PolarsTypes:
polars.Series | polars.DataFrame
- ScipySparseTypes:
ss.csc_matrix | ss.csc_array | ss.csr_matrix | ss.csr_array | ss.coo_matrix | ss.coo_array | ss.dia_matrix | ss.dia_array | ss.lil_matrix | ss.lil_array | ss.dok_matrix | ss.dok_array | ss.bsr_matrix | ss.bsr_array
- XContainer:
NumpyTypes | PandasTypes | PolarsTypes | ScipySparseTypes
Examples
>>> from pybear.base import num_samples >>> import numpy as np >>> X = np.random.randint(0, 10, (5, 4)) >>> num_samples(X) 5