当前位置: 首页>>代码示例>>Python>>正文


Python Vector.magnitude方法代码示例

本文整理汇总了Python中vector.Vector.magnitude方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.magnitude方法的具体用法?Python Vector.magnitude怎么用?Python Vector.magnitude使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vector.Vector的用法示例。


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

示例1: test_normalization

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import magnitude [as 别名]
    def test_normalization(self):
        n = Vector([5.581, -2.136]).normalized()
        self.assertVecEqual(['0.933935214086640320939539156655', '-0.357442325262329993472768036987'], n)
        self.assertEquals(round(n.magnitude(), 1), 1)

        n = Vector([1.996, 3.108, -4.554]).normalized()
        self.assertVecEqual(['0.340401295943301353446730853387', '0.530043701298487295114197490245',
                             '-0.776647044952802834802650679030'], n)
        self.assertEquals(round(n.magnitude(), 1), 1)
开发者ID:calebpowell,项目名称:linear-algebra-py,代码行数:11,代码来源:test_vector.py

示例2: test_magnitude_and_normalize

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import magnitude [as 别名]
def test_magnitude_and_normalize():
    """Quiz 2 calculating magnitude and normalization of Vectors"""
    vector1 = Vector([-0.221, 7.437])
    answer1 = Decimal('7.440')
    assert round(vector1.magnitude(), 3) == answer1

    vector2 = Vector([8.813, -1.331, -6.247])
    answer2 = Decimal('10.884')
    assert round(vector2.magnitude(), 3) == answer2

    vector3 = Vector([5.581, -2.136])
    answer3 = Vector([0.934, -0.357]).round_coords(3)
    assert vector3.normalize().round_coords(3) == answer3

    vector4 = Vector([1.996, 3.108, -4.554])
    answer4 = Vector([0.340, 0.530, -0.777]).round_coords(3)
    assert vector4.normalize().round_coords(3) == answer4
开发者ID:madhavajay,项目名称:ud953,代码行数:19,代码来源:udacity_test.py

示例3: Vector

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import magnitude [as 别名]
from vector import Vector

v = Vector([-0.221, 7.437])
print(v.magnitude())

v = Vector([8.813, -1.331, -6.247])
print(v.magnitude())

v = Vector([5.581, -2.136])
print(v.normalized())

v = Vector([1.996, 3.108, -4.554])
print(v.normalized())

#v = Vector([0, 0])
#print(v.normalized())
开发者ID:aqing1987,项目名称:s-app-layer,代码行数:18,代码来源:test-magnitude-and-direction.py

示例4: Listener

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import magnitude [as 别名]
class Listener(libmyo.DeviceListener):
    """
    Listener implementation. Return False from any function to
    stop the Hub.
    """

    interval = 0.05  # Output only 0.05 seconds
    period = .5 # take data every 1.00 seconds

    def __init__(self):
        super(Listener, self).__init__()
        #self.orientation = None
        #self.pose = libmyo.Pose.rest
        #self.emg_enabled = False
        #self.locked = False
        #self.rssi = None
        #self.emg = None
        self.acceleration = Vector(0, 0, 0)
        self.gyroscope = Vector(0, 0, 0)
        self.last_time = 0
        self.last_data = 0
        #self.acc_x_sum = 0
        self.acc_y_sum = 0
        self.acc_z_sum = 0
        #self.acc_z_raw_sum = 0

        self.acc_mag_sum = 0
        self.gyro_x_sum = 0
        self.gyro_y_sum = 0
        self.gyro_z_sum = 0
        self.gyro_mag_sum = 0
        self.log_gyro_mag_sum = 0

    def output(self):
        ctime = time.time()
        if (ctime - self.last_time) < self.interval:
            return
        self.last_time = ctime

        #acc_x = abs(self.acceleration[0] * 10);
        acc_y = abs(self.acceleration[1] * 10);
        acc_z = abs(self.acceleration[2] * 10);
        #acc_z_raw = self.acceleration[2] * 10;
        acc_mag = self.acceleration.magnitude() * 10;


        gyro_x = abs(self.gyroscope[0]);
        gyro_y = abs(self.gyroscope[1]);
        gyro_z = abs(self.gyroscope[2]);
        gyro_mag = self.gyroscope.magnitude() * 10 ;

        #self.acc_x_sum += acc_x
        self.acc_y_sum += acc_y
        self.acc_z_sum += acc_z
        #self.acc_z_raw_sum += acc_z_raw
        self.acc_mag_sum += acc_mag
        self.gyro_x_sum += gyro_x
        self.gyro_y_sum += gyro_y
        self.gyro_z_sum += gyro_z
        self.gyro_mag_sum += gyro_mag

        if (ctime - self.last_data) > self.period:
            d = (ctime - self.last_data) / self.interval
            parts = []
            #parts.append(self.acc_x_sum/d)
            parts.append(self.acc_y_sum/d)
            parts.append(self.acc_z_sum/d)
            parts.append(self.acc_mag_sum/d)
            parts.append(self.gyro_x_sum/d)
            parts.append(self.gyro_y_sum/d)
            parts.append(self.gyro_z_sum/d)
            parts.append(self.gyro_mag_sum/d)
            #arts.append(self.acc_z_raw_sum/d)

            if self.gyro_mag_sum == 0:
                parts.append(0)
            else:
                parts.append(math.log(self.gyro_mag_sum/d))

            data.append(parts)
            self.last_data = ctime

            self.acc_x_sum = 0
            self.acc_y_sum = 0
            self.acc_z_sum = 0
            #self.acc_z_raw_sum = 0
            self.acc_mag_sum = 0
            self.gyro_x_sum = 0
            self.gyro_y_sum = 0
            self.gyro_z_sum = 0
            self.gyro_mag_sum = 0
            self.log_gyro_mag_sum = 0


        #if self.orientation:
        #    for comp in self.orientation:
        #        parts.append(str(comp).ljust(15))
        #parts.append(str(self.pose).ljust(10))
        #parts.append('E' if self.emg_enabled else ' ')
        #parts.append('L' if self.locked else ' ')
#.........这里部分代码省略.........
开发者ID:acheng96,项目名称:BrickHacks2016-PunchDetectionApp,代码行数:103,代码来源:dataCollection.py

示例5: testMagnitudeOfAVector

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import magnitude [as 别名]
    def testMagnitudeOfAVector(self):
        v1 = Vector([4,4])

        self.assertAlmostEqual(v1.magnitude(), Decimal('5.656854249492380195206754897'))
开发者ID:aenfield,项目名称:UdacityLinearAlgebra,代码行数:6,代码来源:vector_test.py

示例6: Vector

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import magnitude [as 别名]
c = Vector([7.119,8.215])
d = Vector([-8.223,0.878])

e = Vector([1.671,-1.012,-0.318])

f = Vector([-0.221,7.437])
g = Vector([5.581,-2.136])

h = Vector([8.813,-1.331,-6.247])
j = Vector([1.996,3.108,-4.554])


print a + b
print c - d
print e * 7.41
print f.magnitude()
print h.magnitude()
print g.normal()
print j.normal()

print g.normal().magnitude()
print j.normal().magnitude()

# dot product
k,j = Vector([7.887,4.138]),Vector([-8.802,6.776])
l,m = Vector([-5.955,-4.904,-1.874]),Vector([-4.496,-8.755,7.103])

print k.dot(j)
print l.dot(m)

#angle between vectors
开发者ID:vsanjuan,项目名称:algebra,代码行数:33,代码来源:test_cases_vector.py

示例7: test_vector_normalize

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import magnitude [as 别名]
def test_vector_normalize():
    """Test normalizing a Vector"""
    answer = Vector([0.6, 0.8]).round_coords(1)
    assert answer.magnitude() == Decimal('1.0')
    assert VECTOR_3.normalize() == answer
开发者ID:madhavajay,项目名称:ud953,代码行数:7,代码来源:vector_test.py

示例8: Vector

# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import magnitude [as 别名]
print ''
print 'Subtraction'
print v1.minus(v2)

# Scalar Multiplication
s = 7.41
v = Vector([1.671, -1.012, -0.318])
print ''
print 'Scalar Multiplication'
print v.times_scalar(s)

# Magnitude
print ''
print 'Magnitude'
v = Vector([-0.221, 7.437])
print format(v.magnitude(), '.5f')
v = Vector([8.813, -1.331, -6.247])
print format(v.magnitude(), '.5f')

# Normalize
print ''
print 'Normalize'
v = Vector([5.581, -2.136])
print v.normalized()
v = Vector([1.996, 3.108, -4.554])
print v.normalized()

# Dot Product
print ''
print 'Dot Product'
v1 = Vector([7.887, 4.138])
开发者ID:ehafenmaier,项目名称:twd-udacity-la-refresher,代码行数:33,代码来源:lesson.py


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