當前位置: 首頁>>代碼示例>>Python>>正文


Python numpy.var方法代碼示例

本文整理匯總了Python中numpy.var方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.var方法的具體用法?Python numpy.var怎麽用?Python numpy.var使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy的用法示例。


在下文中一共展示了numpy.var方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _lapulaseDetection

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import var [as 別名]
def _lapulaseDetection(self, imgName):
        """
        :param strdir: 文件所在的目錄
        :param name: 文件名稱
        :return: 檢測模糊後的分數
        """
        # step1: 預處理
        img2gray, reImg = self.preImgOps(imgName)
        # step2: laplacian算子 獲取評分
        resLap = cv2.Laplacian(img2gray, cv2.CV_64F)
        score = resLap.var()
        print("Laplacian %s score of given image is %s", str(score))
        # strp3: 繪製圖片並保存  不應該寫在這裏  抽象出來   這是共有的部分
        newImg = self._drawImgFonts(reImg, str(score))
        newDir = self.strDir + "/_lapulaseDetection_/"
        if not os.path.exists(newDir):
            os.makedirs(newDir)
        newPath = newDir + imgName
        # 顯示
        cv2.imwrite(newPath, newImg)  # 保存圖片
        cv2.imshow(imgName, newImg)
        cv2.waitKey(0)

        # step3: 返回分數
        return score 
開發者ID:Leezhen2014,項目名稱:python--,代碼行數:27,代碼來源:BlurDetection.py

示例2: standard_variance

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import var [as 別名]
def standard_variance(data, period):
    """
    Standard Variance.

    Formula:
    (Ct - AVGt)^2 / N
    """
    check_for_period_error(data, period)
    sv = list(map(
        lambda idx:
        np.var(data[idx+1-period:idx+1], ddof=1),
        range(period-1, len(data))
        ))
    sv = fill_for_noncomputable_vals(data, sv)

    return sv 
開發者ID:kkuette,項目名稱:TradzQAI,代碼行數:18,代碼來源:standard_variance.py

示例3: test_runningmeanstd

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import var [as 別名]
def test_runningmeanstd():
    for (x1, x2, x3) in [
        (np.random.randn(3), np.random.randn(4), np.random.randn(5)),
        (np.random.randn(3,2), np.random.randn(4,2), np.random.randn(5,2)),
        ]:

        rms = RunningMeanStd(epsilon=0.0, shape=x1.shape[1:])

        x = np.concatenate([x1, x2, x3], axis=0)
        ms1 = [x.mean(axis=0), x.var(axis=0)]
        rms.update(x1)
        rms.update(x2)
        rms.update(x3)
        ms2 = [rms.mean, rms.var]

        assert np.allclose(ms1, ms2) 
開發者ID:Hwhitetooth,項目名稱:lirpg,代碼行數:18,代碼來源:running_mean_std.py

示例4: test_tf_runningmeanstd

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import var [as 別名]
def test_tf_runningmeanstd():
    for (x1, x2, x3) in [
        (np.random.randn(3), np.random.randn(4), np.random.randn(5)),
        (np.random.randn(3,2), np.random.randn(4,2), np.random.randn(5,2)),
        ]:

        rms = TfRunningMeanStd(epsilon=0.0, shape=x1.shape[1:], scope='running_mean_std' + str(np.random.randint(0, 128)))

        x = np.concatenate([x1, x2, x3], axis=0)
        ms1 = [x.mean(axis=0), x.var(axis=0)]
        rms.update(x1)
        rms.update(x2)
        rms.update(x3)
        ms2 = [rms.mean, rms.var]

        np.testing.assert_allclose(ms1, ms2) 
開發者ID:MaxSobolMark,項目名稱:HardRLWithYoutube,代碼行數:18,代碼來源:running_mean_std.py

示例5: _Variance

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import var [as 別名]
def _Variance(self, imgName):
        """
               灰度方差乘積
               :param imgName:
               :return:
               """
        # step 1 圖像的預處理
        img2gray, reImg = self.preImgOps(imgName)
        f = self._imageToMatrix(img2gray)

        # strp3: 繪製圖片並保存  不應該寫在這裏  抽象出來   這是共有的部分
        score = np.var(f)
        newImg = self._drawImgFonts(reImg, str(score))
        newDir = self.strDir + "/_Variance_/"
        if not os.path.exists(newDir):
            os.makedirs(newDir)
        newPath = newDir + imgName
        cv2.imwrite(newPath, newImg)  # 保存圖片
        cv2.imshow(imgName, newImg)
        cv2.waitKey(0)
        return score 
開發者ID:Leezhen2014,項目名稱:python--,代碼行數:23,代碼來源:BlurDetection.py

示例6: _signal_changepoints_cost_mean

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import var [as 別名]
def _signal_changepoints_cost_mean(signal):
    """Cost function for a normally distributed signal with a changing mean."""
    i_variance_2 = 1 / (np.var(signal) ** 2)
    cmm = [0.0]
    cmm.extend(np.cumsum(signal))

    cmm2 = [0.0]
    cmm2.extend(np.cumsum(np.abs(signal)))

    def cost(start, end):
        cmm2_diff = cmm2[end] - cmm2[start]
        cmm_diff = pow(cmm[end] - cmm[start], 2)
        i_diff = end - start
        diff = cmm2_diff - cmm_diff
        return (diff / i_diff) * i_variance_2

    return cost 
開發者ID:neuropsychology,項目名稱:NeuroKit,代碼行數:19,代碼來源:signal_changepoints.py

示例7: map_fit

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import var [as 別名]
def map_fit(interface, state, label, inp):
    """
    Function counts occurrences of feature values for every row in given data chunk. For continuous features it returns
    number of values and it calculates mean and variance for every feature.
    For discrete features it counts occurrences of labels and values for every feature. It returns occurrences of pairs:
    label, feature index, feature values.
    """
    import numpy as np
    combiner = {}  # combiner used for joining of intermediate pairs
    out = interface.output(0)  # all outputted pairs have the same output label

    for row in inp:  # for every row in data chunk
        row = row.strip().split(state["delimiter"])  # split row
        if len(row) > 1:  # check if row is empty
            for i, j in enumerate(state["X_indices"]):  # for defined features
                if row[j] not in state["missing_vals"]:  # check missing values
                    # creates a pair - label, feature index
                    pair = row[state["y_index"]] + state["delimiter"] + str(j)

                    if state["X_meta"][i] == "c":  # continuous features
                        if pair in combiner:
                            # convert to float and store value
                            combiner[pair].append(np.float32(row[j]))
                        else:
                            combiner[pair] = [np.float32(row[j])]

                    else:  # discrete features
                        # add feature value to pair
                        pair += state["delimiter"] + row[j]
                        # increase counts of current pair
                        combiner[pair] = combiner.get(pair, 0) + 1

                    # increase label counts
                    combiner[row[state["y_index"]]] = combiner.get(row[state["y_index"]], 0) + 1

    for k, v in combiner.iteritems():  # all pairs in combiner are output
        if len(k.split(state["delimiter"])) == 2:  # continous features
            # number of elements, partial mean and variance
            out.add(k, (np.size(v), np.mean(v, dtype=np.float32), np.var(v, dtype=np.float32)))
        else:  # discrete features and labels
            out.add(k, v) 
開發者ID:romanorac,項目名稱:discomll,代碼行數:43,代碼來源:naivebayes.py

示例8: testComputeMovingVars

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import var [as 別名]
def testComputeMovingVars(self):
    height, width = 3, 3
    with self.test_session() as sess:
      image_shape = (10, height, width, 3)
      image_values = np.random.rand(*image_shape)
      expected_mean = np.mean(image_values, axis=(0, 1, 2))
      expected_var = np.var(image_values, axis=(0, 1, 2))
      images = tf.constant(image_values, shape=image_shape, dtype=tf.float32)
      output = ops.batch_norm(images, decay=0.1)
      update_ops = tf.get_collection(ops.UPDATE_OPS_COLLECTION)
      with tf.control_dependencies(update_ops):
        output = tf.identity(output)
      # Initialize all variables
      sess.run(tf.global_variables_initializer())
      moving_mean = variables.get_variables('BatchNorm/moving_mean')[0]
      moving_variance = variables.get_variables('BatchNorm/moving_variance')[0]
      mean, variance = sess.run([moving_mean, moving_variance])
      # After initialization moving_mean == 0 and moving_variance == 1.
      self.assertAllClose(mean, [0] * 3)
      self.assertAllClose(variance, [1] * 3)
      for _ in range(10):
        sess.run([output])
      mean = moving_mean.eval()
      variance = moving_variance.eval()
      # After 10 updates with decay 0.1 moving_mean == expected_mean and
      # moving_variance == expected_var.
      self.assertAllClose(mean, expected_mean)
      self.assertAllClose(variance, expected_var) 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:30,代碼來源:ops_test.py

示例9: testEvalMovingVars

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import var [as 別名]
def testEvalMovingVars(self):
    height, width = 3, 3
    with self.test_session() as sess:
      image_shape = (10, height, width, 3)
      image_values = np.random.rand(*image_shape)
      expected_mean = np.mean(image_values, axis=(0, 1, 2))
      expected_var = np.var(image_values, axis=(0, 1, 2))
      images = tf.constant(image_values, shape=image_shape, dtype=tf.float32)
      output = ops.batch_norm(images, decay=0.1, is_training=False)
      update_ops = tf.get_collection(ops.UPDATE_OPS_COLLECTION)
      with tf.control_dependencies(update_ops):
        output = tf.identity(output)
      # Initialize all variables
      sess.run(tf.global_variables_initializer())
      moving_mean = variables.get_variables('BatchNorm/moving_mean')[0]
      moving_variance = variables.get_variables('BatchNorm/moving_variance')[0]
      mean, variance = sess.run([moving_mean, moving_variance])
      # After initialization moving_mean == 0 and moving_variance == 1.
      self.assertAllClose(mean, [0] * 3)
      self.assertAllClose(variance, [1] * 3)
      # Simulate assigment from saver restore.
      init_assigns = [tf.assign(moving_mean, expected_mean),
                      tf.assign(moving_variance, expected_var)]
      sess.run(init_assigns)
      for _ in range(10):
        sess.run([output], {images: np.random.rand(*image_shape)})
      mean = moving_mean.eval()
      variance = moving_variance.eval()
      # Although we feed different images, the moving_mean and moving_variance
      # shouldn't change.
      self.assertAllClose(mean, expected_mean)
      self.assertAllClose(variance, expected_var) 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:34,代碼來源:ops_test.py

示例10: testReuseVars

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import var [as 別名]
def testReuseVars(self):
    height, width = 3, 3
    with self.test_session() as sess:
      image_shape = (10, height, width, 3)
      image_values = np.random.rand(*image_shape)
      expected_mean = np.mean(image_values, axis=(0, 1, 2))
      expected_var = np.var(image_values, axis=(0, 1, 2))
      images = tf.constant(image_values, shape=image_shape, dtype=tf.float32)
      output = ops.batch_norm(images, decay=0.1, is_training=False)
      update_ops = tf.get_collection(ops.UPDATE_OPS_COLLECTION)
      with tf.control_dependencies(update_ops):
        output = tf.identity(output)
      # Initialize all variables
      sess.run(tf.global_variables_initializer())
      moving_mean = variables.get_variables('BatchNorm/moving_mean')[0]
      moving_variance = variables.get_variables('BatchNorm/moving_variance')[0]
      mean, variance = sess.run([moving_mean, moving_variance])
      # After initialization moving_mean == 0 and moving_variance == 1.
      self.assertAllClose(mean, [0] * 3)
      self.assertAllClose(variance, [1] * 3)
      # Simulate assigment from saver restore.
      init_assigns = [tf.assign(moving_mean, expected_mean),
                      tf.assign(moving_variance, expected_var)]
      sess.run(init_assigns)
      for _ in range(10):
        sess.run([output], {images: np.random.rand(*image_shape)})
      mean = moving_mean.eval()
      variance = moving_variance.eval()
      # Although we feed different images, the moving_mean and moving_variance
      # shouldn't change.
      self.assertAllClose(mean, expected_mean)
      self.assertAllClose(variance, expected_var) 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:34,代碼來源:ops_test.py

示例11: _assert_variance_in_range

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import var [as 別名]
def _assert_variance_in_range(self, initializer, shape, variance,
                                tol=1e-2):
    with tf.Graph().as_default() as g:
      with self.test_session(graph=g) as sess:
        var = tf.get_variable(
            name='test',
            shape=shape,
            dtype=tf.float32,
            initializer=initializer)
        sess.run(tf.global_variables_initializer())
        values = sess.run(var)
        self.assertAllClose(np.var(values), variance, tol, tol) 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:14,代碼來源:hyperparams_builder_test.py

示例12: var

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import var [as 別名]
def var(self):
        return 1 
開發者ID:utra-robosoccer,項目名稱:soccer-matlab,代碼行數:4,代碼來源:filter.py

示例13: std

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import var [as 別名]
def std(self):
        return np.sqrt(self.var) 
開發者ID:utra-robosoccer,項目名稱:soccer-matlab,代碼行數:4,代碼來源:filter.py

示例14: test_running_stat

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import var [as 別名]
def test_running_stat():
    for shp in ((), (3,), (3, 4)):
        li = []
        rs = RunningStat(shp)
        for _ in range(5):
            val = np.random.randn(*shp)
            rs.push(val)
            li.append(val)
            m = np.mean(li, axis=0)
            assert np.allclose(rs.mean, m)
            v = np.square(m) if (len(li) == 1) else np.var(li, ddof=1, axis=0)
            assert np.allclose(rs.var, v) 
開發者ID:utra-robosoccer,項目名稱:soccer-matlab,代碼行數:14,代碼來源:filter.py

示例15: var

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import var [as 別名]
def var(self):
        return self._S/(self._n - 1) if self._n > 1 else np.square(self._M) 
開發者ID:Hwhitetooth,項目名稱:lirpg,代碼行數:4,代碼來源:running_stat.py


注:本文中的numpy.var方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。