def test_0D_array(self):
     a = np.array(1)
     try:
         hsplit(a, 2)
         assert_(0)
     except ValueError:
         pass
Exemple #2
0
 def test_0D_array(self):
     a = np.array(1)
     try:
         hsplit(a, 2)
         assert_(0)
     except ValueError:
         pass
Exemple #3
0
def deal_wave_data(wave_data):
    #wave_data deal by this fuction 
    print wave_data.shape    
    #for the data is stereo,and format is LRLRLR...    
    #shape the array to n*2(-1 means fit the y coordinate)    
    wave_data.shape = -1, 2  
    #transpose the data    
    print wave_data.shape 
    wave_data = wave_data.T  
    hsplit(wave_data[0], 5)
Exemple #4
0
 def readSamples(self, fileName, key,recalc=False,samples=None):
     fn = fileName + ".pre"
     try:
         if recalc: raise IOError()
         with open(fn): pass
         print "precalculated file present"
         self.mu, self.cov = hsplit(mat(fromfile(fn).reshape((3,-1))),[1])
     except IOError:
         if samples != None:
             self._samples = samples
             print "got samples: " , self._samples
         else:
             print "no file present, calculating..."
             smpls = loadmat(fileName)[key]
             print "loaded from mat file"
             self._samples = mat(smpls)
             print "reshaped into samples"
         self.mu = sum(self._samples, axis=1) / self._samples.shape[1]
         print "mu=", str(self.mu)
         sampdiffmu = self._samples - self.mu
         self.cov = sampdiffmu*sampdiffmu.T / self._samples.shape[1]
         print"cov=", str(self.cov)
         mat(hstack((self.mu,self.cov))).tofile(fn)
     self._invCov = self.cov.I
     self._detCov = det(self.cov)
     self._multConst = 1 / sqrt((2 * pi) ** 3 * self._detCov)
 def test_splitting_one_array_into_smaller_arrays(self):
     a = array([[ 8.,  8.,  3.,  9.,  0.,  4.,  3.,  0.,  0.,  6.,  4.,  4.],
                [ 0.,  3.,  2.,  9.,  6.,  0.,  4.,  5.,  7.,  5.,  1.,  4.]])
     b,c,d = hsplit(a,3) # split into three
     numpy.testing.assert_array_equal(b, array([[ 8.,  8.,  3.,  9.],
                                                [ 0.,  3.,  2.,  9.]]))
     numpy.testing.assert_array_equal(c, array([[ 0.,  4.,  3.,  0.],
                                                [ 6.,  0.,  4.,  5.]]))
     numpy.testing.assert_array_equal(d, array([[ 0.,  6.,  4.,  4.],
                                                [ 7.,  5.,  1.,  4.]]))
     e,f,g = hsplit(a,(3,4)) # split after 3 and 4 column
     numpy.testing.assert_array_equal(e, array([[ 8.,  8.,  3.],
                                                [ 0.,  3.,  2.]]))
     numpy.testing.assert_array_equal(f, array([[ 9.],
                                                [ 9.]]))
     numpy.testing.assert_array_equal(g, array([[ 0.,  4.,  3.,  0.,  0.,  6.,  4.,  4.],
                                                [ 6.,  0.,  4.,  5.,  7.,  5.,  1.,  4.]]))
 def test_2D_array(self):
     a = np.array([[1, 2, 3, 4],
                   [1, 2, 3, 4]])
     res = hsplit(a, 2)
     desired = [np.array([[1, 2], [1, 2]]), np.array([[3, 4], [3, 4]])]
     compare_results(res, desired)
Exemple #7
0
 def test_2D_array(self):
     a = np.array([[1, 2, 3, 4],
               [1, 2, 3, 4]])
     res = hsplit(a, 2)
     desired = [np.array([[1, 2], [1, 2]]), np.array([[3, 4], [3, 4]])]
     compare_results(res, desired)