pub fn sample_n(&self, n: usize, with_replacement: bool) -> Result<Self> {
        if !with_replacement && n > self.height() {
            return Err(PolarsError::ShapeMisMatch(
                "n is larger than the number of elements in this array".into(),
            ));
        }
        // all columns should used the same indices. So we first create the indices.
        let idx: NoNull<UInt32Chunked> = match with_replacement {
            true => create_rand_index_with_replacement(n, self.height())
                .1
                .map(|i| i as u32)
                .collect(),
            false => create_rand_index_no_replacement(n, self.height())
                .1
                .map(|i| i as u32)
                .collect(),
        };
        // Safety:
        // indices are withing bounds
        Ok(unsafe { self.take_unchecked(&idx.into_inner()) })
    }
/// Sample n datapoints from this DataFrame.
Sample n datapoints from this DataFrame.
Sample n datapoints from this DataFrame .
pub fn sample_n(&self, n: usize, with_replacement: bool) -> Result<Self> {
        if !with_replacement && n > self.height() {
            return Err(PolarsError::ShapeMisMatch(
                "n is larger than the number of elements in this array".into(),
            ));
        }
        // all columns should used the same indices. So we first create the indices.
        let idx: NoNull<UInt32Chunked> = match with_replacement {
            true => create_rand_index_with_replacement(n, self.height())
                .1
                .map(|i| i as u32)
                .collect(),
            false => create_rand_index_no_replacement(n, self.height())
                .1
                .map(|i| i as u32)
                .collect(),
        };
        // Safety:
        // indices are withing bounds
        Ok(unsafe { self.take_unchecked(&idx.into_inner()) })
    }
pub fn sample_n ( & self , n : usize , with_replacement : bool ) -> Result < Self > { if ! with_replacement && n > self . height ( ) { return Err ( PolarsError :: ShapeMisMatch ( " " . into ( ) , ) ) ; } // all columns should used the same indices. So we first create the indices. let idx : NoNull < UInt32Chunked > = match with_replacement { true => create_rand_index_with_replacement ( n , self . height ( ) ) . 1 . map ( | i | i as u32 ) . collect ( ) , false => create_rand_index_no_replacement ( n , self . height ( ) ) . 1 . map ( | i | i as u32 ) . collect ( ) , } ; // Safety: // indices are withing bounds Ok ( unsafe { self . take_unchecked ( & idx . into_inner ( ) ) } ) }
Sample n datapoints from this DataFrame.
Sample n datapoints from this DataFrame .
&self
n
usize
with_replacement
bool
&self
n
usize
with_replacement
bool