public static IComplexNDArray truncate ( IComplexNDArray nd , int n , int dimension ) { if ( nd . isVector ( ) ) { IComplexNDArray truncated = Nd4j . createComplex ( new int [ ] { 1 , n } ) ; for ( int i = 0 ; i < n ; i ++ ) truncated . putScalar ( i , nd . getComplex ( i ) ) ; return truncated ; } if ( nd . size ( dimension ) > n ) { long [ ] shape = ArrayUtil . copy ( nd . shape ( ) ) ; shape [ dimension ] = n ; IComplexNDArray ret = Nd4j . createComplex ( shape ) ; IComplexNDArray ndLinear = nd . linearView ( ) ; IComplexNDArray retLinear = ret . linearView ( ) ; for ( int i = 0 ; i < ret . length ( ) ; i ++ ) retLinear . putScalar ( i , ndLinear . getComplex ( i ) ) ; return ret ; } return nd ; }
Truncates an ndarray to the specified shape . If the shape is the same or greater it just returns the original array