public List < INDArray > windows ( boolean flattened ) { List < INDArray > ret = new ArrayList <> ( ) ; int window = 0 ; for ( int i = 0 ; i < toSlice . length ( ) ; i ++ ) { if ( window >= toSlice . length ( ) ) break ; double [ ] w = new double [ this . windowRowSize * this . windowColumnSize ] ; for ( int count = 0 ; count < this . windowRowSize * this . windowColumnSize ; count ++ ) { w [ count ] = toSlice . getDouble ( count + window ) ; } INDArray add = Nd4j . create ( w ) ; if ( flattened ) add = add . ravel ( ) ; else add = add . reshape ( windowRowSize , windowColumnSize ) ; if ( addRotate ) { INDArray currRotation = add . dup ( ) ; //3 different orientations besides the original for ( int rotation = 0 ; rotation < 3 ; rotation ++ ) { Nd4j . rot90 ( currRotation ) ; ret . add ( currRotation . dup ( ) ) ; } } window += this . windowRowSize * this . windowColumnSize ; ret . add ( add ) ; } return ret ; }
Moving window capture a row x column moving window of a given matrix