title: Sorting 3d arrays in python as per grid
body: <p>I have grid points in 3d and I would like to sort them based (x,y,z) using python (if possible avoiding loops)..</p>
  
  <p>For example if the input is,<br>
  (1,2,1), (0,8,1), (1,0,0) ..<br>
  then output should be<br>
  (0,8,1), (1,0,0), (1,2,1)..</p>
  
  <hr>
  
  <p>Sorry for this side track but I am actually doing is reading from a file which has data in following way:<br>
  x y z f(x) f(y) f(z)..
  what I was doing was following:</p>
  
  <pre><code>def fill_array(output_array,source_array,nx,ny,nz,position):
  for i in range(nx):
      for j in range(ny):
          for k in range(nz):
              output_array[i][j][k] = source_array[i][j][k][position]
  nx = 8
  ny = 8
  nz = 8
  
  ndim = 6
  
  x = np.zeros((nx,ny,nz))
  y = np.zeros((nx,ny,nz))
  z = np.zeros((nx,ny,nz))
  bx = np.zeros((nx,ny,nz))
  by = np.zeros((nx,ny,nz))
  bz = np.zeros((nx,ny,nz))
  
  data_file = np.loadtxt('datafile')
  f = np.reshape(data_file, (nx,ny,nz,ndim))
  fill_array(x,f,nx,ny,nz,0))
  fill_array(y,f,nx,ny,nz,1)
  fill_array(z,f,nx,ny,nz,2)
  fill_array(fx,f,nx,ny,nz,3)
  fill_array(fy,f,nx,ny,nz,4)
  fill_array(fz,f,nx,ny,nz,5)
  </code></pre>
  
  <p>This was working fine when data was arranged (as explained previously) but with file written not in order it is creating problems with plot later on. Is there are better way to do this ? Of course I only want to arrange x,y,z and then associate functional value f(x),f(y),f(z) to its right position (x,y,z)</p>
  
  <p>two updates<br>
  1) i am getting following error when I use sorted with either x,y,z,fx,fy,fz or f.    </p>
  
  <pre><code>ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
  </code></pre>
  
  <p>2) i need it in that specific way because I am using mayavi then for contour3d</p>