python中迭代_在python中迭代的最快方法

到目前为止,我从来没有关心过这个问题,但是现在我需要使用一些需要被PyOpenGL缓冲的顶点,而且好像python迭代是瓶颈。这是情况。我有一个3D点vertices的数组,每一步我都必须为每个顶点计算一个4D的颜色数组。我到目前为止的做法是:

upper_border = len(self.vertices) / 3

#Only generate at first step, otherwise use old one and replace values

if self.color_array is None:

self.color_array = numpy.empty(4 * upper_border)

for i in range(upper_border):

#Obtain a color between a start->end color

diff_activity = (activity[i] - self.min) / abs_diff

clr_idx = i * 4

self.color_array[clr_idx] = start_colors[0] + diff_activity * end_colors[0]

self.color_array[clr_idx + 1] = start_colors[1] + diff_activity * end_colors[1]

self.color_array[clr_idx + 2] = start_colors[2] + diff_activity * end_colors[2]

self.color_array[clr_idx + 3] = 1现在我不认为我可以做什么来消除循环中每个步骤的操作,但我猜测必须有一个更优化的性能方式来完成该循环。我在说,因为在JavaScript中,例如,同样的微积分产生9FPS,而在Python中,我只得到2-3 FPS。

问候,

波格丹

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值