pub fn sample_n(&self, n: usize, with_replacement: bool) -> Result<Self> {
        if !with_replacement && n > self.len() {
            return Err(PolarsError::ShapeMisMatch(
                "n is larger than the number of elements in this array".into(),
            ));
        }
        let len = self.len();

        match with_replacement {
            true => {
                let (_, iter) = create_rand_index_with_replacement(n, len);
                // Safety we know that we never go out of bounds
                debug_assert_eq!(len, self.len());
                unsafe { Ok(self.take_unchecked(iter.into())) }
            }
            false => {
                let (_, iter) = create_rand_index_no_replacement(n, len);
                // Safety we know that we never go out of bounds
                debug_assert_eq!(len, self.len());
                unsafe { Ok(self.take_unchecked(iter.into())) }
            }
        }
    }
/// Sample n datapoints from this ChunkedArray.
Sample n datapoints from this ChunkedArray.
Sample n datapoints from this ChunkedArray .
pub fn sample_n(&self, n: usize, with_replacement: bool) -> Result<Self> {
        if !with_replacement && n > self.len() {
            return Err(PolarsError::ShapeMisMatch(
                "n is larger than the number of elements in this array".into(),
            ));
        }
        let len = self.len();
        match with_replacement {
            true => {
                let (_, iter) = create_rand_index_with_replacement(n, len);
                // Safety we know that we never go out of bounds
                debug_assert_eq!(len, self.len());
                unsafe { Ok(self.take_unchecked(iter.into())) }
            }
            false => {
                let (_, iter) = create_rand_index_no_replacement(n, len);
                // Safety we know that we never go out of bounds
                debug_assert_eq!(len, self.len());
                unsafe { Ok(self.take_unchecked(iter.into())) }
            }
        }
    }
pub fn sample_n ( & self , n : usize , with_replacement : bool ) -> Result < Self > { if ! with_replacement && n > self . len ( ) { return Err ( PolarsError :: ShapeMisMatch ( " " . into ( ) , ) ) ; } let len = self . len ( ) ; match with_replacement { true => { let ( _ , iter ) = create_rand_index_with_replacement ( n , len ) ; // Safety we know that we never go out of bounds debug_assert_eq ! ( len self len ( ) ) ; unsafe { Ok ( self . take_unchecked ( iter . into ( ) ) ) } } false => { let ( _ , iter ) = create_rand_index_no_replacement ( n , len ) ; // Safety we know that we never go out of bounds debug_assert_eq ! ( len self len ( ) ) ; unsafe { Ok ( self . take_unchecked ( iter . into ( ) ) ) } } } }
Sample n datapoints from this ChunkedArray.
Sample n datapoints from this ChunkedArray .
&self
n
usize
with_replacement
bool
&self
n
usize
with_replacement
bool