gt:     	Dataset lt = Comparisons.lessThan(a, 0.5);
context: /*-
   *******************************************************************************
   * Copyright (c) 2011, 2014 Diamond Light Source Ltd.
   * All rights reserved. This program and the accompanying materials
   * are made available under the terms of the Eclipse Public License v1.0
   * which accompanies this distribution, and is available at
   * http://www.eclipse.org/legal/epl-v10.html
   *
   * Contributors:
   *    Matthew Gerring - initial API and implementation and/or initial documentation
   *******************************************************************************/
  package org.eclipse.dawnsci.analysis.examples.dataset;
  
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.List;
  
  import org.eclipse.dawnsci.analysis.api.dataset.IDataset;
  import org.eclipse.dawnsci.analysis.api.dataset.Slice;
  import org.eclipse.dawnsci.analysis.dataset.impl.BooleanDataset;
  import org.eclipse.dawnsci.analysis.dataset.impl.Comparisons;
  import org.eclipse.dawnsci.analysis.dataset.impl.Dataset;
  import org.eclipse.dawnsci.analysis.dataset.impl.DatasetFactory;
  import org.eclipse.dawnsci.analysis.dataset.impl.DatasetUtils;
  import org.eclipse.dawnsci.analysis.dataset.impl.DoubleDataset;
  import org.eclipse.dawnsci.analysis.dataset.impl.FFT;
  import org.eclipse.dawnsci.analysis.dataset.impl.LinearAlgebra;
  import org.eclipse.dawnsci.analysis.dataset.impl.Maths;
  import org.eclipse.dawnsci.analysis.dataset.impl.Random;
  import org.junit.Before;
  import org.junit.Test;
  
  
  /**
   * How to do the basics, see <a href="http://wiki.scipy.org/NumPy_for_Matlab_Users">NumPy for Matlab Users</a>.
   * <p>
   * These examples are done as tests because it is easy to run the code.
   * However they are examples and do not actively test anything.
   *
   * @author Matthew Gerring
   *
   */
  public class NumpyExamples {
  	
  	/**
  	 * IDataset is like ndarray
  	 */
  	private Dataset a, b, c, v;
  
  	@Before
  	public void create() {
  		a = new DoubleDataset(new double[]{1,2,3,6,4,5,8,9,7}, 3, 3);
  		b = new DoubleDataset(new double[]{1.1,2.2,3.3,4.4,5.5,6.6}, 2, 3);
  		c = new DoubleDataset(new double[]{1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8,9.9}, 3, 3);
  		v = new DoubleDataset(new double[]{7,1,9});
  	}
  	
  	/**
  	 * What follows in comments:
  	 * 
  	 * MATLAB CODE         NUMPY VECTOR  NUMPY MATRIX (may be unset)
  	 */
  	
  	/**
  	 * ndims(a)            ndim(a) or a.adim
  	 */
  	@Test
  	public void ndims() {
  		System.out.println("a has rank "+a.getRank());
  	}
  	
  	/**
  	 * numel(a)            size(a) or a.size
  	 */
  	@Test
  	public void size() {
  		System.out.println("a has size "+a.getSize());
  	}
  	
  	/**
  	 * size(a,n)           a.shape[n-1]
  	 */
  	@Test
  	public void sizeN() {
  		System.out.println("a has size "+a.getShape()[0]);
  	}
  	
  	/**
  	 * 2x3 matrix literal
  	 * [ 1 2 3; 4 5 6 ]     array([[1.,2.,3.],[4.,5.,6.]])
  	 */
  	@Test
  	public void createMatrix() {
  		IDataset set = new DoubleDataset(new double[]{1,2,3,4,5,6}, 2,3);
  		System.out.println("Created a dataset : "+set);
  	}
  	
  	/**
  	 * construct a matrix from blocks a,b,c, and d
  	 * 
  	 * [ a b; c d ]              vstack([hstack([a,b]), hstack([c,d])])
  	 */
  	@Test
  	public void concatenate() {
  		
  		IDataset h1 = DatasetUtils.concatenate(new IDataset[]{a,c},   1);
  
  		IDataset c = new DoubleDataset(new double[]{1,2,3,4,5,6}, 2, 3);
  		IDataset d = new DoubleDataset(new double[]{1,2,3,4,5,6}, 2, 3);
  		IDataset h2 = DatasetUtils.concatenate(new IDataset[]{c,d},   1);
  		IDataset m  = DatasetUtils.concatenate(new IDataset[]{h1,h2}, 0);
  		
  		System.out.println("Created matrix from blocks "+m);
  	}
  	
  	/**
  	 * access last element in the 1xn matrix a
  	 * a(end)                     a[-1]   or    a[:,-1][0,0]
  	 */
  	@Test
  	public void lastElement() {
  		// a is 2x3 but the -1 principle for the end is still valid.
  		double val = a.getDouble(-1,-1);
  		System.out.println("The last value is "+val);
  	}
  	
  	/**
  	 * access element in second row, fifth column
  	 * a(2,5)                     a[1,4]
  	 */
  	@Test
  	public void element1x4() {
  		// a is 2x3 so we make a bigger one
  		a = Random.rand(new int[]{10, 10});
  		
  		// Get 1,4
  		double val = a.getDouble(1,4);
  		System.out.println("The last value at (1,4) "+val);
  	}
  	
  	/** entire second row of a
  	 * a(2,:)                     a[1] or a[1,:]
  	 */
  	@Test
  	public void entireRow() {
  		IDataset set = a.getSliceView(new Slice(1,2));
  		System.out.println("The row at index 1 is "+set);
  	}
  	
  	/**the first five rows of a
  	 * a(1:5,:)                   a[0:5] or a[:5] or a[0:5,:]
  	 */
  	@Test
  	public void fiveRows() {
  		
  		// a is 2x3 so we make a bigger one
  		a = Random.rand(new int[]{10, 10});
  		
  		IDataset set = a.getSliceView(new Slice(5));
  		System.out.println("The shape of five rows is "+set);
  
  	}
  	
  	/**the last five rows of a
  	 * a(end-4:end,:)             a[-5:]
  	 */
  	@Test
  	public void lastFiveRows() {
  		// a is 2x3 so we make a bigger one
  		a = Random.rand(new int[]{10, 10});
  		
  		IDataset set = a.getSliceView(new Slice(-5,null));
  		System.out.println("The shape of last five rows is "+set);
  		
  	}
  	
  	/**rows one to three and columns five to nine of a. This gives read-only access.
  	 * a(1:3,5:9)                 a[0:3][:,4:9]
  
  	 */
  	@Test
  	public void subslice() {
  		// a is 2x3 so we make a bigger one
  		a = Random.rand(new int[]{10, 10});
  		
  		IDataset set = a.getSliceView(new Slice(0,3), new Slice(4,9));
  		System.out.println("The shape of the slice is "+set);
  		
  	}
  	
  	/**every other row of a, starting with the third and going to the twenty-first
  	 * (3:2:21,:)                 a[ 2:21:2,:]
  	 */
  	@Test
  	public void everyOther() {
  		
  		// a is 2x3 so we make a bigger one
  		a = Random.rand(new int[]{21, 10});
  
  		IDataset set = a.getSliceView(new Slice(2,21,2), null);
  		System.out.println("The shape of the slice is "+set);
  
  	}
  	
  	/**every other row of a, starting with the first
  	 * a(1:2:end,:)                a[ ::2,:]
  	 * */
  	@Test
  	public void everyOther2() {
  		
  		// a is 2x3 so we make a bigger one
  		a = Random.rand(new int[]{21, 10});
  
  		IDataset set = a.getSliceView(new Slice(null,null,2), null);
  		System.out.println("The shape of the everyother slice is "+set);
  	}
  
  	/**	a with rows in reverse order
  	 * a(end:-1:1,:) or flipud(a)           a[ ::-1,:]
  	 * **/
  	@Test
  	public void reverseOrder() {
  		// a is 2x3 so we make a bigger one
  		a = Random.rand(new int[]{21, 10});
  
  		IDataset set = a.getSliceView(new Slice(null,null,-1), null);
  		System.out.println("The shape of the reversed slice is "+set);
  
  	}
  	
  	/**a with copy of the first row appended to the end
  	 * a([1:end 1],:)                       a[r_[:len(a),0]]
  	 **/
      @Test
      public void appendLast() {
      	IDataset first = a.getSlice(new Slice(0,1), null);
      	IDataset aplus = DatasetUtils.append(a, first, 0);
      	
      	System.out.println("a with the first column added to the end is "+aplus);
      }
      
      /**transpose of a
       * a.'                                   a.transpose() or a.T
       */
      @Test
      public void transpose() {
      	IDataset trans = a.getTransposedView();
      	System.out.println("a transposed is "+trans);
      }
      
      /**conjugate transpose of a
       * a'                                   a.conj().transpose() or a.conj().T       a.H
       */
      @Test
      public void conjTranspose() {
      	IDataset ct = Maths.conjugate(a).getTransposedView();
      	System.out.println("a conjugate transposed is "+ct);
      }
      
      /**element-wise multiply
       * a .* b                               a * b             multiply(a,b)
       */
      @Test
      public void multiply() {
      	
      	IDataset c = Maths.multiply(a, b);
         	System.out.println("Multiply element-wise to new array is "+c);
  
          a.imultiply(b);
         	System.out.println("Multiply element-wise on a is "+a);
      }
      
      
      /** element-wise divide
       * a ./ b                               a / b
       */
      @Test
      public void divide() {
      	
      	IDataset c = Maths.divide(a, b);
         	System.out.println("Divide element-wise to new array is "+c);
  
          a.idivide(b);
         	System.out.println("Divide element-wise on a is "+a);
      }
  
      /**element-wise exponentiation
       * a.^3                                 a**3    power(a,3)
       */   
      @Test
      public void exp() {
      	
      	IDataset c = Maths.power(a, 3);
         	System.out.println("Exponent element-wise to new array is "+c);
  
          a.ipower(3);
         	System.out.println("Exponent element-wise on a is "+a);
      }
      
      /**matrix whose i,jth element is (a_ij > 0.5)
       * (a>0.5)                              (a>0.5)
       */
      @Test
      public void matrixTest1() {
      	Dataset g = Comparisons.greaterThan(a, 0.5);
      	System.out.println("" + a.getByBoolean(g));
      }
      
      /**extract the columms of a where vector v > 0.5
      a(:,find(v>0.5))                        a[:,nonzero(v>0.5)[0]]   a[:,nonzero(v.A>0.5)[0]]
      **/
      @Test
      public void matrixTest2() {
      	Dataset v = Random.rand(3);
      	Dataset nz = Comparisons.nonZero(Comparisons.greaterThan(v, 0.5)).get(0);
      	System.out.println("" + a.getByIndexes(null, nz));
      }
      
      
      /** extract the columms of a where column vector v > 0.5 
       * a(:,find(v>0.5))                      a[:,v.T>0.5]       a[:,v.T>0.5)]
       */
      @Test
      public void matrixTest3() {
      	Dataset v = Random.rand(new int[] {3, 1});
      	Dataset nz = Comparisons.nonZero(Comparisons.greaterThan(( v).getTransposedView(), 0.5)).get(0);
      	System.out.println("" + a.getByIndexes(null, nz));
      }
      
      /**a with elements less than 0.5 zeroed out
       * a(a<0.5)=0                            a[a<0.5]=0
       */
      @Test
      public void zeroedLt() {
  