• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python numpy.absolute函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中numpy.absolute函数的典型用法代码示例。如果您正苦于以下问题:Python absolute函数的具体用法?Python absolute怎么用?Python absolute使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了absolute函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: paddingAnswers

def paddingAnswers(answerSheet1, blankSheet1):
   numRowsA, numColsA, numBandsA, dataTypeA = ipcv.dimensions(answerSheet1)
   numRowsB, numColsB, numBandsB, dataTypeB = ipcv.dimensions(blankSheet1)
   print numRowsB, numColsB
   if numBandsA == 3:
      answerSheet = cv2.cvtColor(answerSheet1, cv.CV_BGR2GRAY)
   elif numBandsA == 1:
      answerSheet = answerSheet1

   if numBandsB == 3:
      blankSheet = cv2.cvtColor(blankSheet1, cv.CV_BGR2GRAY)
   elif numBandsB == 1:
      blankSheet = blankSheet1  

   pad = numpy.absolute(numRowsA - numColsA)/2.0
   maxCount = numpy.max(blankSheet)

   if (numRowsA-numColsA) % 2 != 0:
      answerSheet = numpy.pad(answerSheet, ((0,0),(pad,pad+1)), 'constant', constant_values=((maxCount, maxCount),(maxCount,maxCount)))
   elif (numRowsA-numColsA) % 2 == 0:
      answerSheet = numpy.pad(answerSheet, ((0,0),(pad,pad)), 'constant', constant_values=((maxCount, maxCount),(maxCount,maxCount)))

   pad1 = numpy.absolute(numRowsB - numColsB)/2.0
   maxCount = numpy.max(blankSheet)

   if (numRowsB-numColsB) % 2 != 0:
      blankSheet = numpy.pad(blankSheet, ((0,0),(pad1,pad1+1)), 'constant', constant_values=((maxCount, maxCount),(maxCount,maxCount)))
   elif (numRowsA-numColsA) % 2 == 0:
      blankSheet = numpy.pad(blankSheet, ((0,0),(pad1,pad1)), 'constant', constant_values=((maxCount, maxCount),(maxCount,maxCount)))


   return answerSheet, blankSheet
开发者ID:jordanwesthoff,项目名称:scantron,代码行数:32,代码来源:paddingAnswers.py


示例2: plotall

 def plotall(self):
     real = self.z_data_raw.real
     imag = self.z_data_raw.imag
     real2 = self.z_data_sim.real
     imag2 = self.z_data_sim.imag
     fig = plt.figure(figsize=(15,5))
     fig.canvas.set_window_title("Resonator fit")
     plt.subplot(131)
     plt.plot(real,imag,label='rawdata')
     plt.plot(real2,imag2,label='fit')
     plt.xlabel('Re(S21)')
     plt.ylabel('Im(S21)')
     plt.legend()
     plt.subplot(132)
     plt.plot(self.f_data*1e-9,np.absolute(self.z_data_raw),label='rawdata')
     plt.plot(self.f_data*1e-9,np.absolute(self.z_data_sim),label='fit')
     plt.xlabel('f (GHz)')
     plt.ylabel('Amplitude')
     plt.legend()
     plt.subplot(133)
     plt.plot(self.f_data*1e-9,np.unwrap(np.angle(self.z_data_raw)),label='rawdata')
     plt.plot(self.f_data*1e-9,np.unwrap(np.angle(self.z_data_sim)),label='fit')
     plt.xlabel('f (GHz)')
     plt.ylabel('Phase')
     plt.legend()
     # plt.gcf().set_size_inches(15,5)
     plt.tight_layout()
     plt.show()
开发者ID:vdrhtc,项目名称:resonator_tools,代码行数:28,代码来源:utilities.py


示例3: getEnergy

    def getEnergy(self, normalized=True, mask=None):
        """
        Returns the current energy.

        Parameters:
            normalized: Flag to return the normalized energy (that is, divided
            by the total density)
        """
        if self.gpu:
            psi = self.psi.get()
            V = self.Vdt.get() / self.dt
        else:
            psi = self.psi
            V = self.Vdt.get() / self.dt
        density = np.absolute(psi) ** 2
        gradx = np.gradient(psi)[0]
        normFactor = density.sum() if normalized else 1.0
        return (
            np.ma.array(
                -(
                    0.25 * np.gradient(np.gradient(density)[0])[0]
                    - 0.5 * np.absolute(gradx) ** 2
                    - (self.g_C * density + V) * density
                ),
                mask=mask,
            ).sum()
            / normFactor
        )
开发者ID:danielct,项目名称:Honours,代码行数:28,代码来源:Simulator.py


示例4: mask_good

def mask_good(m, badval = UNSEEN, rtol = 1.e-5, atol = 1.e-8):
    """Return a mask with False where m is close to badval
    and True elsewhere
    [absolute(m - badval) > atol + rtol * absolute(badval)]"""
    atol = npy.absolute(atol)
    rtol = npy.absolute(rtol)
    return npy.absolute(m - badval) > atol + rtol * npy.absolute(badval)
开发者ID:Alwnikrotikz,项目名称:healpy,代码行数:7,代码来源:pixelfunc.py


示例5: add_data

def add_data(N):
    if N<=37.0:
        Ns=N
    else:
        Ns=37.0
    X=Ns*pi*(f-f0)/f0
    A=sin(X)/sin(X/Ns)
    #ans=recur_exp(N, Np=37) 
    
    #A=sum([el[0]*exp(1j*2*pi*f/f0*el[1])/1.0 for el in ans])
    #A=sum([1.0*exp(1j*2*pi*f/f0*el[1])/1.0 for el in ans])

    #A=comb_A(N)
    Asq=absolute(A)**2
    #return Asq
    Ga0=2*mu**2*Y0*Ns**2
    Ga=Ga0*Asq/Ns**2
    Ba=Ga0*(sin(2*X)-2*X)/(2*X**2)
    w=2*pi*f
    S13=1j*sqrt(2*Ga*GL)/(Ga+1j*Ba+1j*w*C+GL)
#
#    if N>5:
#        Ns=N-5
#    else: 
#        Ns=1
#    X=Ns*pi*(f-f0)/f0
#    A=1*sin(X)/sin(X/Ns)
#    Asq=A**2
#    Ga0=2*mu**2*Y0*(Ns)**2
#    Ga=Ga0*Asq/Ns**2
#    Ba=Ga0*(sin(2*X)-2*X)/(2*X**2)
#    w=2*pi*f
#    S31=1j*sqrt(2*Ga*GL)/(Ga+1j*Ba+1j*w*C+GL)
#        
    return absolute(S13**2)
开发者ID:thomasaref,项目名称:TA_software,代码行数:35,代码来源:D0703_osc_test.py


示例6: mask_good

def mask_good(m, badval=UNSEEN, rtol=1.0e-5, atol=1.0e-8):
    """Returns a bool array with ``False`` where m is close to badval.

    Parameters
    ----------
    m : a map (may be a sequence of maps)
    badval : float, optional
        The value of the pixel considered as bad (:const:`UNSEEN` by default)
    rtol : float, optional
        The relative tolerance
    atol : float, optional
        The absolute tolerance

    Returns
    -------
    a bool array with the same shape as the input map, ``False`` where input map is
    close to badval, and ``True`` elsewhere.

    See Also
    --------
    mask_bad, ma

    Examples
    --------
    >>> import healpy as hp
    >>> m = np.arange(12.)
    >>> m[3] = hp.UNSEEN
    >>> hp.mask_good(m)
    array([ True,  True,  True, False,  True,  True,  True,  True,  True,
            True,  True,  True], dtype=bool)
    """
    m = np.asarray(m)
    atol = np.absolute(atol)
    rtol = np.absolute(rtol)
    return np.absolute(m - badval) > atol + rtol * np.absolute(badval)
开发者ID:jrs65,项目名称:healpy,代码行数:35,代码来源:pixelfunc.py


示例7: calculateMie

def calculateMie(data):
    # Extract data
    (p, w, n_p, n_medium, th, n_theta, x_rv) = data
    # Size parameter
    # x      - size parameter = k*radius = 2pi/lambda * radius
    #          (lambda is the wavelength in the medium around the scatterers)
    x = np.pi * p / (w / n_medium)
    # Mie parameters
    (S1, S2, Qext, Qsca, Qback, gsca) = bhmie(x, n_p / n_medium, n_theta)
    # Phase function
    P = (np.absolute(S1) ** 2.0 + np.absolute(S2) ** 2.0) / \
        (Qsca * x ** 2.0)
    # Cumulative distribution
    cP = st.cumulativeDistributionTheta(P, th)
    # Normalize
    cP /= cP[-1]

    # Inverse cumulative distribution for random variable picking
    cPinv = st.invertNiceFunction(np.degrees(th), cP, x_rv)

    pD = {}
    pD['particleDiameter'] = p
    pD['sizeParameter'] = x
    pD['wavelength'] = w
    pD['crossSections'] = Qext * np.pi * (p / 2.0) ** 2.0
    pD['inverseCDF'] = cPinv
    pD['phaseFunction'] = P
    pD['cumulativePhaseFunction'] = cP

    # Return generated data
    return pD
开发者ID:ollitapa,项目名称:VTT-Raytracer,代码行数:31,代码来源:mieGenerator.py


示例8: curvature_optimisation_func_lensmaker

def curvature_optimisation_func_lensmaker(curv_1 = 0.002, focal_length = 100.,
                                diameter = 5., thickness = 5., ref_index = 1.5):
    """
    This function is used to minimise the RMS spread of a beam of given
    diameter, propagated through a lens of given thickness, by changing
    the curvatures of the two sides of the lens. It is meant to be used
    in conjunction with an optimisation function.
    
    This function is bounded by the lensmaker equation, so it only requires
    one curvature as an argument and the other is calculated using the
    given focal length, thickness, and refractive index.
    """
    curv_2 = lensmaker_equation(curv_1, focal_length, thickness, ref_index)
    if curv_2 == 0:
        curv_2 -= 1e-13
    if curv_1 == 0:
        curv_1 += 1e-13
    aperture_radius_1 = np.absolute(1/float(curv_1))
    aperture_radius_1 -= 1e-6*aperture_radius_1
    aperture_radius_2 = np.absolute(1/float(curv_2))
    aperture_radius_2 -= 1e-6*aperture_radius_2
    lens_front = opt.SphericalRefraction(focal_length, curv_1, 
                                        aperture_radius_1, 1., ref_index)
    lens_back = opt.SphericalRefraction(focal_length + thickness, 
                                        curv_2, aperture_radius_2, 
                                        ref_index, 1.)
    max_radius = diameter/2.
    test_beam = rt.CollimatedBeam([0,0,0], [0,0,1], 6, max_radius, 2)
    rms_spread = rms_xy_spread([lens_front, lens_back], focal_length, test_beam)
    return np.log10(rms_spread)
开发者ID:msfstef,项目名称:Optical-Ray-Tracer,代码行数:30,代码来源:analysis.py


示例9: estimate

def estimate(data):
    length=len(data)
    wave=thinkdsp.Wave(ys=data,framerate=Fs)
    spectrum=wave.make_spectrum()
    spectrum_heart=wave.make_spectrum()
    spectrum_resp=wave.make_spectrum()

    fft_mag=list(np.absolute(spectrum.hs))
    fft_length= len(fft_mag)

    spectrum_heart.high_pass(cutoff=0.8,factor=0.001)
    spectrum_heart.low_pass(cutoff=2,factor=0.001)
    fft_heart=list(np.absolute(spectrum_heart.hs))

    max_fft_heart=max(fft_heart)
    heart_sample=fft_heart.index(max_fft_heart)
    hr=heart_sample*Fs/length*60

    spectrum_resp.high_pass(cutoff=0.15,factor=0)
    spectrum_resp.low_pass(cutoff=0.4,factor=0)
    fft_resp=list(np.absolute(spectrum_resp.hs))

    max_fft_resp=max(fft_resp)
    resp_sample=fft_resp.index(max_fft_resp)
    rr=resp_sample*Fs/length*60
    
    print "Heart Rate:", hr, "BPM"
    
    if hr<10:
        print "Respiration Rate: 0 RPM"
    else:
        print "Respiration Rate:", rr, "RPM"
    
    return
开发者ID:harshul1610,项目名称:med_10,代码行数:34,代码来源:RealTime_Everything.py


示例10: compareRecon

def compareRecon(recon1, recon2):
    ''' compare two arrays and return 1 is they are the same within specified
        precision and 0 if not.
        function was made to accompany unit test code '''
    ## FIX: make precision a input parameter
    prec = -11   # desired precision
    if recon1.shape != recon2.shape:
        print 'shape is different!'
        print recon1.shape
        print recon2.shape
        return 0

    for i in range(recon1.shape[0]):
        for j in range(recon2.shape[1]):
            if numpy.absolute(recon1[i,j].real - recon2[i,j].real) > math.pow(10,-11):
                print "real: i=%d j=%d %.15f %.15f diff=%.15f" % (i, j, recon1[i,j].real, recon2[i,j].real, numpy.absolute(recon1[i,j].real-recon2[i,j].real))
                return 0
            ## FIX: need a better way to test
            # if we have many significant digits to the left of decimal we 
            #   need to be less stringent about digits to the right.
            # The code below works, but there must be a better way.
            if isinstance(recon1, complex):
                if int(math.log(numpy.abs(recon1[i,j].imag), 10)) > 1:
                    prec = prec + int(math.log(numpy.abs(recon1[i,j].imag), 10))
                    if prec > 0:
                        prec = -1
                print prec
                if numpy.absolute(recon1[i,j].imag - recon2[i,j].imag) > math.pow(10, prec):
                    print "imag: i=%d j=%d %.15f %.15f diff=%.15f" % (i, j, recon1[i,j].imag, recon2[i,j].imag, numpy.absolute(recon1[i,j].imag-recon2[i,j].imag))
                    return 0

    return 1
开发者ID:LabForComputationalVision,项目名称:pyPyrTools,代码行数:32,代码来源:compareRecon.py


示例11: isEqual

def isEqual(left, right, eps=None, masked_equal=True):
  ''' This function checks if two numpy arrays or scalars are equal within machine precision, and returns a scalar logical. '''
  diff_type = "Both arguments to function 'isEqual' must be of the same class!"
  if isinstance(left,np.ndarray):
    # ndarray
    if not isinstance(right,np.ndarray): raise TypeError(diff_type)
    if not left.dtype==right.dtype:
      right = right.astype(left.dtype) # casting='same_kind' doesn't work...
    if np.issubdtype(left.dtype, np.inexact): # also catch float32 etc
      if eps is None: return ma.allclose(left, right, masked_equal=masked_equal)
      else: return ma.allclose(left, right, masked_equal=masked_equal, atol=eps)
    elif np.issubdtype(left.dtype, np.integer) or np.issubdtype(left.dtype, np.bool):
      return np.all( left == right ) # need to use numpy's all()
  elif isinstance(left,(float,np.inexact)):
    # numbers
    if not isinstance(right,(float,np.inexact)): raise TypeError(diff_type)
    if eps is None: eps = 100.*floateps # default
    if ( isinstance(right,float) or isinstance(right,float) ) or left.dtype.itemsize == right.dtype.itemsize: 
      return np.absolute(left-right) <= eps
    else:
      if left.dtype.itemsize < right.dtype.itemsize: right = left.dtype.type(right)
      else: left = right.dtype.type(left)
      return np.absolute(left-right) <= eps  
  elif isinstance(left,(int,bool,np.integer,np.bool)):
    # logicals
    if not isinstance(right,(int,bool,np.integer,np.bool)): raise TypeError(diff_type)
    return left == right
  else: raise TypeError(left)
开发者ID:xiefengy,项目名称:GeoPy,代码行数:28,代码来源:misc.py


示例12: _exec_loop_moving_window

    def _exec_loop_moving_window(self, a_all, bd_all, mask, bd_idx):
        """Solves the kriging system by looping over all specified points.
        Less memory-intensive, but involves a Python-level loop."""
        import scipy.linalg.lapack

        npt = bd_all.shape[0]
        n = bd_idx.shape[1]
        zvalues = np.zeros(npt)
        sigmasq = np.zeros(npt)

        for i in np.nonzero(~mask)[0]:   # Note that this is the same thing as range(npt) if mask is not defined,
            b_selector = bd_idx[i]       # otherwise it takes the non-masked elements.
            bd = bd_all[i]

            a_selector = np.concatenate((b_selector, np.array([a_all.shape[0] - 1])))
            a = a_all[a_selector[:, None], a_selector]

            if np.any(np.absolute(bd) <= self.eps):
                zero_value = True
                zero_index = np.where(np.absolute(bd) <= self.eps)
            else:
                zero_index = None
                zero_value = False
            b = np.zeros((n+1, 1))
            b[:n, 0] = - self.variogram_function(self.variogram_model_parameters, bd)
            if zero_value:
                b[zero_index[0], 0] = 0.0
            b[n, 0] = 1.0

            x = scipy.linalg.solve(a, b)

            zvalues[i] = x[:n, 0].dot(self.Z[b_selector])
            sigmasq[i] = - x[:, 0].dot(b[:, 0])

        return zvalues, sigmasq
开发者ID:yejingxin,项目名称:PyKrige,代码行数:35,代码来源:ok.py


示例13: _exec_loop

    def _exec_loop(self, a, bd_all, mask):
        """Solves the kriging system by looping over all specified points.
        Less memory-intensive, but involves a Python-level loop."""

        npt = bd_all.shape[0]
        n = self.X_ADJUSTED.shape[0]
        zvalues = np.zeros(npt)
        sigmasq = np.zeros(npt)

        a_inv = scipy.linalg.inv(a)

        for j in np.nonzero(~mask)[0]:   # Note that this is the same thing as range(npt) if mask is not defined,
            bd = bd_all[j]               # otherwise it takes the non-masked elements.
            if np.any(np.absolute(bd) <= self.eps):
                zero_value = True
                zero_index = np.where(np.absolute(bd) <= self.eps)
            else:
                zero_index = None
                zero_value = False

            b = np.zeros((n+1, 1))
            b[:n, 0] = - self.variogram_function(self.variogram_model_parameters, bd)
            if zero_value:
                b[zero_index[0], 0] = 0.0
            b[n, 0] = 1.0
            x = np.dot(a_inv, b)
            zvalues[j] = np.sum(x[:n, 0] * self.Z)
            sigmasq[j] = np.sum(x[:, 0] * -b[:, 0])

        return zvalues, sigmasq
开发者ID:yejingxin,项目名称:PyKrige,代码行数:30,代码来源:ok.py


示例14: _exec_vector

    def _exec_vector(self, a, bd, mask):
        """Solves the kriging system as a vectorized operation. This method
        can take a lot of memory for large grids and/or large datasets."""

        npt = bd.shape[0]
        n = self.X_ADJUSTED.shape[0]
        zero_index = None
        zero_value = False

        a_inv = scipy.linalg.inv(a)

        if np.any(np.absolute(bd) <= self.eps):
            zero_value = True
            zero_index = np.where(np.absolute(bd) <= self.eps)

        b = np.zeros((npt, n+1, 1))
        b[:, :n, 0] = - self.variogram_function(self.variogram_model_parameters, bd)
        if zero_value:
            b[zero_index[0], zero_index[1], 0] = 0.0
        b[:, n, 0] = 1.0

        if (~mask).any():
            mask_b = np.repeat(mask[:, np.newaxis, np.newaxis], n+1, axis=1)
            b = np.ma.array(b, mask=mask_b)

        x = np.dot(a_inv, b.reshape((npt, n+1)).T).reshape((1, n+1, npt)).T
        zvalues = np.sum(x[:, :n, 0] * self.Z, axis=1)
        sigmasq = np.sum(x[:, :, 0] * -b[:, :, 0], axis=1)

        return zvalues, sigmasq
开发者ID:yejingxin,项目名称:PyKrige,代码行数:30,代码来源:ok.py


示例15: niceformat

def niceformat(x, l, s):
    """Get a nice formatted string of a number.

    Parameters:
        x: scalar
        l: boolean
            latex expression if True else ordinary
        s: boolean
            use '$' if True else don't

    Returns: expr
        expr: string
            string representing the number
            no measure unit
    """
    if l:
        pref = PREFIXES.copy()
        if s:
            pref[-6] = r'$\mu$'
        else:
            pref[-6] = r'\mu'
    else:
        pref = PREFIXES 
    xexp = 0
    while np.absolute(x) < 1 and xexp >= min(PREFIXES.keys()):
        xexp -= 3
        x *= 1000.
    while np.absolute(x) >= 1e3 and xexp <= max(PREFIXES.keys()):
        xexp += 3
        x /= 1000.
    s = '%.4g'%x + ' ' + pref[xexp]
    return s
开发者ID:alesslazzari,项目名称:eledp,代码行数:32,代码来源:utils.py


示例16: det_trace_iter

def det_trace_iter(A, v, E):
    """
    :param A: input matrix
    :param v: vector used for power method
    :param E: tolerance parameter
    :return: (determinant, trace, N) ->determinant, trace, number of iterations
    """
    N = 0
    err = 0
    lamda = 0
    while np.absolute(err) >= np.absolute(lamda * E) and N <= 100:
        N += 1
        temp = matrix_multiply(A, v)
        newlamda = matrix_multiply(np.transpose(v), temp)[0, 0]
        newlamda = newlamda / matrix_multiply(np.transpose(v), v)[0, 0]

        # can we use magnitude method???
        err = np.absolute(newlamda - lamda)
        v = temp
        lamda = newlamda
    # does multiple multiplication for power method!!!
    if np.absolute(err) < np.absolute(lamda * E):
        return (determinant_for_2x2(A), trace(A), N)
    else:
        #print("Uhh, failed")
        return None
开发者ID:kkawaguchi3,项目名称:math2605-fall15-project,代码行数:26,代码来源:matrix_operations.py


示例17: callback

def callback(data):
    # trouble shoot - print data from subscriber
    #rospy.loginfo(rospy.get_caller_id() + "leftx: %s, rightx: %s", data.leftx, data.rightx)    
    
	# unpack values
    global m1val
    global m2val
    global xl 
    global xr
    xlnew = float(data.leftx);
    xrnew = float(data.rightx);

    if(numpy.absolute(xlnew-xl) < 0.02):
        xl = xlnew;
    #else:
    	#print('invalid x1, not updated')

    if(numpy.absolute(xrnew-xr) < 0.02):
        xr = xrnew;
    #else:
    	#print('invalid x2, not updated')




    xlcm = xl * 100;
    xrcm = xr * 100;
    #print 'leftx: {0:.3f} cm, rightx: {1:.3f} cm.'.format(xlcm, xrcm)

    # read currents
    m1cur, m2cur = readcurrents();
开发者ID:dwong229,项目名称:gitcatkin_ws,代码行数:31,代码来源:controller_inputvector.py


示例18: crunchy2

def crunchy2(pt_and_sigma, sec, hand=None):
    pt, sigma = pt_and_sigma
    py, px = pt

    powers = []
    powers_norm = []

    y_axis = sec.get_y_axis()
    x_axis = sec.get_x_axis()
    px_y = np.absolute(y_axis[1] - y_axis[0])
    px_x = np.absolute(x_axis[1] - x_axis[0])

    if sigma == None:
        sigma = [px_y, px_x]
    if sigma[0] < px_y:
        sigma = [px_y, sigma[1]]
    if sigma[1] < px_x:
        sigma = [sigma[0], px_x]

    for yi in range(len(y_axis)):
        y = y_axis[yi]
        for xi in range(len(x_axis)):
            x = x_axis[xi]
            this_weight = weight_function2(y, x, py, px, sigma)
            if this_weight is None:
                powers.append(None)
                powers_norm.append(None)
            else:
                variance = 1 / this_weight
                powers.append(sec.get([yi, xi]) / variance)
                powers_norm.append(1 / variance)
    p = np.nansum(list(filter(None, powers)))
    pn = np.nansum(list(filter(None, powers_norm)))
    return pt, p / pn
开发者ID:haukejung,项目名称:pulsarpkg,代码行数:34,代码来源:multiprocessing_helper_functions.py


示例19: plotCoeff

def plotCoeff(X, y, obj, featureNames, whichReg):
    """ Plot Regression's Coeff
    """
    clf = classifiers[whichReg]
    clf,_,_ = fitAlgo(clf, X,y, opt= True, param_dict = param_dist_dict[whichReg])
    if whichReg == "LogisticRegression":
    	coeff = np.absolute(clf.coef_[0])
    else:
    	coeff = np.absolute(clf.coef_)
    print coeff
    indices = np.argsort(coeff)[::-1]
    print indices
    print featureNames
    featureList = []
    # num_features = len(featureNames)
    print("Feature ranking:")
    for f in range(num_features):
        featureList.append(featureNames[indices[f]])
        print("%d. feature %s (%.2f)" % (f, featureNames[indices[f]], coeff[indices[f]]))
    fig = pl.figure(figsize=(8,6),dpi=150)
    pl.title("Feature importances",fontsize=30)
    # pl.bar(range(num_features), coeff[indices],
    #         yerr = std_importance[indices], color=paired[0], align="center",
    #         edgecolor=paired[0],ecolor=paired[1])
    pl.bar(range(num_features), coeff[indices], color=paired[0], align="center",
            edgecolor=paired[0],ecolor=paired[1])
    pl.xticks(range(num_features), featureList, size=15,rotation=90)
    pl.ylabel("Importance",size=30)
    pl.yticks(size=20)
    pl.xlim([-1, num_features])
    # fix_axes()
    pl.tight_layout()
    save_path = 'plots/'+obj+'/'+whichReg+'_feature_importances.pdf'
    fig.savefig(save_path)
开发者ID:rexshihaoren,项目名称:MSPrediction-Python,代码行数:34,代码来源:EnjoyLifePred.py


示例20: crunchy3

def crunchy3(offset, eta, sec, sigma=None):
    powers = []
    powers_norm = []

    y_axis = sec.get_y_axis()
    x_axis = sec.get_x_axis()
    px_y = np.absolute(y_axis[1] - y_axis[0])
    px_x = np.absolute(x_axis[1] - x_axis[0])

    if sigma is None:
        sigma = [px_y, px_x]
    if sigma[0] < px_y:
        sigma = [px_y, sigma[1]]
    if sigma[1] < px_x:
        sigma = [sigma[0], px_x]

    for yi in range(len(y_axis)):
        y = y_axis[yi]
        for xi in range(len(x_axis)):
            x = x_axis[xi]
            y_eff = y + eta * offset ** 2
            x_eff = x - offset
            this_weight = weight_function3(eta, y, x, y_eff, x_eff, sigma)
            if this_weight is None:
                powers.append(None)
                powers_norm.append(None)
            else:
                variance = 1 / this_weight
                powers.append(sec.get([yi, xi]) / variance)
                powers_norm.append(1 / variance)
    p = np.nansum(list(filter(None, powers)))
    pn = np.nansum(list(filter(None, powers_norm)))
    return offset, p / pn
开发者ID:haukejung,项目名称:pulsarpkg,代码行数:33,代码来源:multiprocessing_helper_functions.py



注:本文中的numpy.absolute函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python numpy.acos函数代码示例发布时间:2022-05-27
下一篇:
Python numpy.abs函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap