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

Python Numeric.array函数代码示例

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

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



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

示例1: __call__

    def __call__(self,action=None):
        if action==None:
            self.angle = self.initial_angle
            self.velocity = self.initial_velocity
            return array((self.angle,self.velocity))
        else:
            if type(action) == ArrayType:
                action = action[0]
            self.last_action = action
            # setup constants
            m = self.mass
            g = self.g
            l = self.length
            dt = self.delta_t
            
            # Gravitational torque
            T_g = m * g * l * cos(pi/2-self.angle)
            # action torque
            T_a = action

            # rotational acceleration is Torque divided by moment-of-inertia
            a = (T_g + T_a)/(m*l)

            # update velocity from acceleration (including friction)
            self.velocity += (a * dt)
            self.velocity -= self.velocity * self.friction

            # update angle from velocity
            self.angle += (self.velocity * dt)/2

            return (array((normalize_angle(self.angle),self.velocity)),self.reward())
开发者ID:ronaldahmed,项目名称:robot-navigation,代码行数:31,代码来源:pendulum.py


示例2: setData

 def setData(self, *args):
     if len(args) == 3:
         self.locns, self.vals, self.sigs = args
         if len(locns) != len(vals) or len(vals) != len(sigs):
             raise DataError, 'Mismatch in lengths of arguments!'
     elif len(args) == 1:
         all = args[0]
         try:
             rows, cols = all.shape
             self.locns = all[:,0]
             self.vals = all[:,1]
             self.sigs = all[:,2]
         except AttributeError:
             # If *all* is not an array, treat it as a list.
             # Only the list format can handle >1-d locns using
             # a single setData argument.
             self.locns, self.vals, self.sigs = [], [], []
             for row in all:
                 self.locns.append(row[0])
                 self.vals.append(row[1])
                 self.sigs.append(row[2])
             self.locns = array(self.locns)
             self.vals = array(self.vals)
             self.sigs = array(self.sigs)
         except:
             raise DataError, 'Bad data array format!'
     self.ndata = len(vals)
     if len(self.locns.shape) == 1:
         self.dimen = 1
     elif len(self.locns.shape) ==2:
         self.dimen = self.locns.shape[1]
     else:
         raise DataError, 'Locations should be scalars or 1-d arrays!'
开发者ID:tloredo,项目名称:inference,代码行数:33,代码来源:Param1.py


示例3: test__add_

 def test__add_(self):
     """__add__: should not normalize input or output, just add"""
     p1 = Profile(array([[.3,.4,.1,0],[.1,.1,.1,.7]]),Alphabet="ABCD")
     p2 = Profile(array([[1,0,0,0],[1,0,0,1]]),Alphabet="ABCD")
     self.assertEqual((p1+p2).Data, array([[1.3,.4,.1,0],[1.1,.1,.1,1.7]]))
     self.assertRaises(ProfileError,self.empty.__add__, p1)
     self.assertEqual((self.empty + self.empty).Data.tolist(),[[]])
开发者ID:pombredanne,项目名称:old-cogent,代码行数:7,代码来源:test_profile.py


示例4: test_toOddsMatrix

 def test_toOddsMatrix(self):
     """toOddsMatrix: should work on valid data or raise an error
     """
     p = Profile(array([[.1,.3,.5,.1],[.25,.25,.25,.25],\
         [.05,.8,.05,.1],[.7,.1,.1,.1],[.6,.15,.05,.2]]),\
         Alphabet="ACTG")
     p_exp = Profile(array([[.4, 1.2, 2, .4],[1,1,1,1],[.2,3.2,.2,.4],\
         [2.8,.4,.4,.4],[2.4,.6,.2,.8]]),Alphabet="ACTG")
     self.assertEqual(p.toOddsMatrix().Data,p_exp.Data)
     assert p.Alphabet is p.toOddsMatrix().Alphabet
     self.assertEqual(p.toOddsMatrix([.25,.25,.25,.25]).Data,p_exp.Data)
     
     #fails if symbol_freqs has wrong size
     self.assertRaises(ProfileError, p.toOddsMatrix,\
         [.25,.25,.25,.25,.25,.25])
     self.assertRaises(ProfileError, self.zero_entry.toOddsMatrix,\
         [.1,.2,.3])
     #works on empty profile
     self.assertEqual(self.empty.toOddsMatrix().Data.tolist(),[[]])
     #works with different input
     self.assertEqual(self.zero_entry.toOddsMatrix().Data,\
         array([[1.2,.8,0,2],[0,0,3.2,.8]]))
     self.assertFloatEqual(self.zero_entry.toOddsMatrix([.1,.2,.3,.4]).Data,\
         array([[3,1,0,1.25],[0,0,2.667,.5]]),1e-3)
     #fails when one of the background frequencies is 0
     self.assertRaises(ProfileError, self.zero_entry.toOddsMatrix,\
         [.1,.2,.3,0])
开发者ID:pombredanne,项目名称:old-cogent,代码行数:27,代码来源:test_profile.py


示例5: test4

def test4():
    test = HMM(['a','b'],['s1','s2','s3'],
               array([[.3,.5],[.7,.5]]),
               array([[.5,0],[.5,.5],[0,.5]]),
               array([.9,.1]))
    print test.simulate(10)
    print test.simulate(10,1)
开发者ID:pruan,项目名称:TestDepot,代码行数:7,代码来源:hmm.py


示例6: test_score_profile

    def test_score_profile(self):
        """score: should work correctly for Profile as input
        """
        p1 = Profile(array([[1,0,0,0],[0,1,0,0],[0,0,.5,.5],[0,0,0,1],\
            [.25,.25,.25,.25]]),"TCAG")
        p2 = Profile(array([[0,1,0,0],[.2,0,.8,0],[0,0,.5,.5],[1/3,1/3,0,1/3],\
            [.25,.25,.25,.25]]),"TCAG")
        p3 = Profile(array([[1,0,0,0],[0,1,0,0],[0,0,0,1]]),"TCAG")
        p4 = Profile(array([[1,0,0,0],[0,1,0,0]]),"TCAG")
        p5 = Profile(array([[1,0,0,0],[0,1,0,0],[0,0,0,1]]),"AGTC")

        #works on normal valid data
        self.assertFloatEqual(self.score2.score(p1,offset=0),\
            [.55,1.25,.45])
        self.assertFloatEqual(self.score2.score(p2,offset=0),
            [1.49,1.043,.483],1e-3)
        #works with different offset
        self.assertFloatEqual(self.score2.score(p1,offset=1),
            [1.25,0.45])
        self.assertFloatEqual(self.score2.score(p1,offset=2),
            [0.45])
        #raises error on invalid offset 
        self.assertRaises(ProfileError,self.score2.score,\
            p1,offset=3)
        #works on profile of minimal length
        self.assertFloatEqual(self.score2.score(p3,offset=0),
            [0.6])
        #raises error when profile is too short
        self.assertRaises(ProfileError, self.score2.score,p4,offset=0)
        #raises error on empty profile
        self.assertRaises(ProfileError,self.empty.score,p1)
        #raises error when character order doesn't match
        self.assertRaises(ProfileError,self.score2.score,p5) 
开发者ID:pombredanne,项目名称:old-cogent,代码行数:33,代码来源:test_profile.py


示例7: __init__

 def __init__(self, *args, **kwargs):
     Visualiser.__init__(self, *args, **kwargs)
     fin = NetCDFFile(self.vis_source, 'r')
     self.xPoints = array(fin.variables['x'], Float)
     self.yPoints = array(fin.variables['y'], Float)
     self.quantityCache = {}
     fin.close()
开发者ID:MattAndersonPE,项目名称:anuga_core,代码行数:7,代码来源:sww_visualiser.py


示例8: test_pairs_to_array

    def test_pairs_to_array(self):
        """pairs_to_array should match hand-calculated results"""
        p2a = pairs_to_array
        p1 = [0, 1, 0.5]
        p2 = [2, 3, 0.9]
        p3 = [1, 2, 0.6]
        pairs = [p1, p2, p3]
        self.assertEqual(p2a(pairs), \
            array([[0,.5,0,0],[0,0,.6,0],[0,0,0,.9],[0,0,0,0]]))
        #try it without weights -- should assign 1
        new_pairs = [[0,1],[2,3],[1,2]]
        self.assertEqual(p2a(new_pairs), \
            array([[0,1,0,0],[0,0,1,0],[0,0,0,1],[0,0,0,0]]))
        #try it with explicit array size
        self.assertEqual(p2a(pairs, 5), \
            array([[0,.5,0,0,0],[0,0,.6,0,0],[0,0,0,.9,0],[0,0,0,0,0],\
            [0,0,0,0,0]]))
        #try it when we want to map the indices into gapped coords
        #we're effectively doing ABCD -> -A--BC-D-
        transform = array([1,4,5,7])
        result = p2a(pairs, transform=transform)
        self.assertEqual(result.shape, (8,8))
        exp = zeros((8,8), Float64)
        exp[1,4] = 0.5
        exp[4,5] = 0.6
        exp[5,7] = 0.9
        self.assertEqual(result, exp)

        result = p2a(pairs, num_items=9, transform=transform)
        self.assertEqual(result.shape, (9,9))
        exp = zeros((9,9), Float64)
        exp[1,4] = 0.5
        exp[4,5] = 0.6
        exp[5,7] = 0.9
        self.assertEqual(result, exp)
开发者ID:pombredanne,项目名称:old-cogent,代码行数:35,代码来源:test_array.py


示例9: distance_to_closest

def distance_to_closest(alignment, distance_method=hamming_distance):
    """Returns vector of distances to closest neighbor for each s in alignment
    
    alignment: Alignment object
    distance_method: function used to calculate the distance between two seqs
    
    Function returns the closest distances according to the RowOrder in the
    alignment

    example:
    Alignment({1:'ABCD',2:'ABCC',3:'CBDD',4:'ACAA'},RowOrder=[3,2,1,4])
    [2,1,1,3]
    """
    #change sequences into arrays
    for item in alignment:
        alignment[item] = array(alignment[item])
    
    closest = []
    for key in alignment.RowOrder:
        seq = alignment[key]
        dist = None
        for other_key in alignment.RowOrder:
            if key == other_key:
                continue
            d = distance_method(seq,alignment[other_key])
            if dist:
                if d < dist:
                    dist = d
            else:
                dist = d
        closest.append(dist)
    return array(closest)
开发者ID:pombredanne,项目名称:old-cogent,代码行数:32,代码来源:util.py


示例10: test_ungapped_to_gapped

 def test_ungapped_to_gapped(self):
     """ungapped_to_gapped should match hand-calculated results"""
     u2g = ungapped_to_gapped
     self.assertEqual(u2g(self.s1, '-'), array([0,1,2,4]))
     self.assertEqual(u2g(self.s2, '-'), array([2,3]))
     self.assertEqual(u2g(self.s3, '-'), array([0,1]))
     self.assertEqual(u2g(self.s4, '-'), array([0,1]))
     self.assertEqual(u2g(self.s5, '-'), array([]))
开发者ID:pombredanne,项目名称:old-cogent,代码行数:8,代码来源:test_array.py


示例11: test_unmasked_to_masked

 def test_unmasked_to_masked(self):
     """unmasked_to_masked should match hand-calculated results"""
     u2m = unmasked_to_masked
     self.assertEqual(u2m(self.m1), array([0,1,2,4]))
     self.assertEqual(u2m(self.m2), array([2,3]))
     self.assertEqual(u2m(self.m3), array([0,1]))
     self.assertEqual(u2m(self.m4), array([0,1]))
     self.assertEqual(u2m(self.m5), array([]))
开发者ID:pombredanne,项目名称:old-cogent,代码行数:8,代码来源:test_array.py


示例12: distance

    def distance(self,other):
        """Calculates the distance between two BaseUsages.

        Distance is measured in three directions, CG-content, CU-content, and
        GU-content.
        """
        return euclidean_distance(array(self.toCartesian()),\
            array(other.toCartesian()))
开发者ID:pombredanne,项目名称:old-cogent,代码行数:8,代码来源:usage.py


示例13: test_center_of_mass_two_array

 def test_center_of_mass_two_array(self):
     """center_of_mass_two_array should behave correctly"""
     com2 = center_of_mass_two_array
     coor = take(self.square_odd,(0,1),1)
     weights = take(self.square_odd,(2,),1)
     self.assertEqual(com2(coor,weights), array([2,2]))
     weights = weights.flat
     self.assertEqual(com2(coor,weights), array([2,2]))
开发者ID:pombredanne,项目名称:old-cogent,代码行数:8,代码来源:test_geometry.py


示例14: setUp

 def setUp(self):
     """setUp for all CenterOfMass tests"""
     self.simple = array([[1,1,1],[3,1,1],[2,3,2]])
     self.simple_list = [[1,1,1],[3,1,1],[2,3,2]]
     self.more_weight = array([[1,1,3],[3,1,3],[2,3,50]])
     self.square = array([[1,1,25],[3,1,25],[3,3,25],[1,3,25]])
     self.square_odd = array([[1,1,25],[3,1,4],[3,3,25],[1,3,4]])
     self.sec_weight = array([[1,25,1],[3,25,1],[3,25,3],[1,25,3]])
开发者ID:pombredanne,项目名称:old-cogent,代码行数:8,代码来源:test_geometry.py


示例15: __init__

 def __init__(self, stacks, position):
     """
     Pass a reference to the stacks object that holds all the blocks
     and the index of the initial stack of the block
     """
     Block.__init__(self, stacks, position)
     self.box = box(pos=(position-(stacks.blockCount/2), 0, 0), size=(.9,.9,.9), color=color.blue)
     self.label = label(pos=array(self.box.pos) + array([0,0,1]), text=str(position), opacity=0, box=0, line=0)
开发者ID:bhramoss,项目名称:code,代码行数:8,代码来源:recipe-361168.py


示例16: testAngleBetween

 def testAngleBetween(self):
     vector1 = array((1, 0, 0))
     vector2 = array((0, 1, 0))
     angle = angleBetween(vector1, vector2)
     assert angle == 90, "Fails sanity check"
     assert alltrue(vector1 == array((1, 0, 0))) and \
            alltrue(vector2 == array((0, 1, 0))), \
            "Arguments were modified (recurrence of bug ####)"
开发者ID:ematvey,项目名称:NanoEngineer-1,代码行数:8,代码来源:VQT_Test.py


示例17: optimize

 def optimize(self):
     """Optimize the objective function with respect to varying params."""
     p, d = [], []
     for param in self.varyingParams:
         p.append(param.getValue())
         d.append(param.delta)
     p = array(p)
     d = identity(len(d)) * array(d,Float)
     return powell(self._objective, p, drxns=d)
开发者ID:tloredo,项目名称:inference,代码行数:9,代码来源:Param.py


示例18: hermite

def hermite(x0, x1, v0, v1, t):
    a = array([1, t, t**2, t**3])
    M = array([[1, 0, 0, 0],
               [1, 1, 1, 1],
               [0, 1, 0, 0],
               [0, 1, 2, 3]])
    p = transpose([[x0, x1, v0, v1]])

    return dot(dot(a, inverse(M)), p)
开发者ID:Open-Technology,项目名称:Computational-Biology,代码行数:9,代码来源:splines.py


示例19: test_euclidean_distance

 def test_euclidean_distance(self):
     """euclidean_distance: should return dist between 2 vectors or matrices
     """
     a = array([3,4])
     b = array([8,5])
     c = array([[2,3],[4,5]])
     d = array([[1,5],[8,2]])
     self.assertFloatEqual(euclidean_distance(a,b),sqrt(26))
     self.assertFloatEqual(euclidean_distance(c,d),sqrt(30))
开发者ID:pombredanne,项目名称:old-cogent,代码行数:9,代码来源:test_array.py


示例20: __init__

 def __init__(self, x, y=None, z=None):
     if y is None and z is None:
         # Array, list, tuple...
         if len(x)!=3:
             raise "Vector: x is not a list/tuple/array of 3 numbers"
         self._ar=array(x, 'd')
     else:
         # Three numbers
         self._ar=array((x, y, z), 'd')
开发者ID:dbmi-pitt,项目名称:DIKB-Evidence-analytics,代码行数:9,代码来源:Vector.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python Numeric.dot函数代码示例发布时间:2022-05-24
下一篇:
Python NumWrap.zeros函数代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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