Exemplo n.º 1
0
 def _mul_scalar(self, other):
     res_dtype = upcast_scalar(self.dtype, other)
     # Multiply this scalar by every element.
     new = dok_matrix(self.shape, dtype=res_dtype)
     for (key, val) in iteritems(self):
         new[key] = val * other
     return new
Exemplo n.º 2
0
 def _mul_scalar(self, other):
     res_dtype = upcast_scalar(self.dtype, other)
     # Multiply this scalar by every element.
     new = dok_matrix(self.shape, dtype=res_dtype)
     for (key, val) in iteritems(self):
         new[key] = val * other
     return new
Exemplo n.º 3
0
 def transpose(self):
     """ Return the transpose
     """
     M, N = self.shape
     new = dok_matrix((N, M), dtype=self.dtype)
     for key, value in iteritems(self):
         new[key[1], key[0]] = value
     return new
Exemplo n.º 4
0
 def conjtransp(self):
     """ Return the conjugate transpose
     """
     M, N = self.shape
     new = dok_matrix((N, M), dtype=self.dtype)
     for key, value in iteritems(self):
         new[key[1], key[0]] = np.conj(value)
     return new
Exemplo n.º 5
0
 def __itruediv__(self, other):
     if isscalarlike(other):
         # Multiply this scalar by every element.
         for (key, val) in iteritems(self):
             self[key] = val / other
         return self
     else:
         return NotImplemented
Exemplo n.º 6
0
 def transpose(self):
     """ Return the transpose
     """
     M, N = self.shape
     new = dok_matrix((N, M), dtype=self.dtype)
     for key, value in iteritems(self):
         new[key[1], key[0]] = value
     return new
Exemplo n.º 7
0
 def _mul_multivector(self, other):
     # matrix * multivector
     M, N = self.shape
     n_vecs = other.shape[1]  # number of column vectors
     result = np.zeros((M, n_vecs), dtype=upcast(self.dtype, other.dtype))
     for (i, j), v in iteritems(self):
         result[i, :] += v * other[j, :]
     return result
Exemplo n.º 8
0
 def conjtransp(self):
     """ Return the conjugate transpose
     """
     M, N = self.shape
     new = dok_matrix((N, M), dtype=self.dtype)
     for key, value in iteritems(self):
         new[key[1], key[0]] = np.conj(value)
     return new
Exemplo n.º 9
0
 def __itruediv__(self, other):
     if isscalarlike(other):
         # Multiply this scalar by every element.
         for (key, val) in iteritems(self):
             self[key] = val / other
         return self
     else:
         return NotImplemented
Exemplo n.º 10
0
 def _mul_multivector(self, other):
     # matrix * multivector
     M,N = self.shape
     n_vecs = other.shape[1]  # number of column vectors
     result = np.zeros((M,n_vecs), dtype=upcast(self.dtype,other.dtype))
     for (i,j),v in iteritems(self):
         result[i,:] += v * other[j,:]
     return result
Exemplo n.º 11
0
 def __imul__(self, other):
     if isscalarlike(other):
         # Multiply this scalar by every element.
         for (key, val) in iteritems(self):
             self[key] = val * other
         # new.dtype.char = self.dtype.char
         return self
     else:
         return NotImplemented
Exemplo n.º 12
0
 def __imul__(self, other):
     if isscalarlike(other):
         # Multiply this scalar by every element.
         for (key, val) in iteritems(self):
             self[key] = val * other
         # new.dtype.char = self.dtype.char
         return self
     else:
         return NotImplemented
Exemplo n.º 13
0
 def __str__(self):
     ss = "%s\n" % self.__class__
     for key, val in iteritems(self.__dict__):
         if (issubclass(self.__dict__[key].__class__, Struct)):
             ss += "  %s:\n    %s\n" % (key, self.__dict__[key].__class__)
         else:
             aux = "\n" + str(val)
             aux = aux.replace("\n", "\n    ")
             ss += "  %s:\n%s\n" % (key, aux[1:])
     return(ss.rstrip())
Exemplo n.º 14
0
 def __truediv__(self, other):
     if isscalarlike(other):
         new = dok_matrix(self.shape, dtype=self.dtype)
         # Multiply this scalar by every element.
         for (key, val) in iteritems(self):
             new[key] = val / other
         #new.dtype.char = self.dtype.char
         return new
     else:
         return self.tocsr() / other
Exemplo n.º 15
0
 def __str__(self):
     ss = "%s\n" % self.__class__
     for key, val in iteritems(self.__dict__):
         if (issubclass(self.__dict__[key].__class__, Struct)):
             ss += "  %s:\n    %s\n" % (key, self.__dict__[key].__class__)
         else:
             aux = "\n" + str(val)
             aux = aux.replace("\n", "\n    ")
             ss += "  %s:\n%s\n" % (key, aux[1:])
     return (ss.rstrip())
Exemplo n.º 16
0
 def __truediv__(self, other):
     if isscalarlike(other):
         new = dok_matrix(self.shape, dtype=self.dtype)
         # Multiply this scalar by every element.
         for (key, val) in iteritems(self):
             new[key] = val / other
         # new.dtype.char = self.dtype.char
         return new
     else:
         return self.tocsr() / other
Exemplo n.º 17
0
def dok_lt(self, other):
    """
    Element-wise greater than
    """
    # First, store all the non-trivial elements
    ret = sp.dok_matrix(self, dtype = bool, copy = True)
    for (key, val) in iteritems(self):
        ret[key] = val < other
    
    # TODO: dok_matrix by default returns 0.0 for unknown keys
    # this should be replaced by either False for bool arrays 
    # OR, better, a default setting, either True or False
    return ret
x = data['ENTRIESn_hourly'][data['rain'] == 0]
y = data['ENTRIESn_hourly'][data['rain'] == 1]


# As there was an issue with the scipy.stats.mannwhitneyu(y,x) which gave a nan p-value, I had to copy/paste the
# calculating functions instead of using directly scipy.stats.mannwhitneyu(x,y)

use_continuity = True
x = ma.asarray(x).compressed().view(ndarray)
y = ma.asarray(y).compressed().view(ndarray)
ranks = rankdata(np.concatenate([x,y]))
(nx, ny) = (len(x), len(y))
nt = nx + ny
U = ranks[:nx].sum() - nx*(nx+1)/2.
U = max(U, nx*ny - U)
u = nx*ny - U
#
mu = (nx*ny)/2.
sigsq = (nt**3 - nt)/12.
ties = count_tied_groups(ranks)
sigsq -= np.sum(v*(k**3-k) for (k,v) in iteritems(ties))/12.
sigsq *= nx*ny/float(nt*(nt-1))

if use_continuity:
    z = (U - 1/2. - mu) / ma.sqrt(sigsq)
else:
    z = (U - mu) / ma.sqrt(sigsq)
prob = special.erfc(abs(z)/np.sqrt(2))

print "p-value : " + str(prob)
Exemplo n.º 19
0
 def _mul_vector(self, other):
     # matrix * vector
     result = np.zeros(self.shape[0], dtype=upcast(self.dtype, other.dtype))
     for (i, j), v in iteritems(self):
         result[i] += v * other[j]
     return result
Exemplo n.º 20
0
 def _mul_vector(self, other):
     # matrix * vector
     result = np.zeros(self.shape[0], dtype=upcast(self.dtype,other.dtype))
     for (i,j),v in iteritems(self):
         result[i] += v * other[j]
     return result