数字Python问题 [英] Numerical Python question

查看:54
本文介绍了数字Python问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Python和Numerical Python的新手。我有一个程序在另一个程序中写了

,它广泛使用了数组。我正在尝试将
转换为Python。


假设使用Numerical Python中的数组,其内容为

DOW Jones Industrial的每日开盘价,最高价,最低价和最后价格

其整个历史的平均价格。如何在整个

整个数组中迭代计算每日高价的10天平均价格或每日低价格的价格?


如果有人可以编写一些伪代码,指出我在

正确的方向,我会非常感激。


谢谢。

解决方案

mc*****@bigfoot.com (2mc)之前写过:

|在Numerical Python中假设一个数组,其中的内容是

| DOW的每日开盘价,最高价,最低价和最后价。 Jones Industrial

|其整个历史的平均值。


我不确定阵列中各个高点和低点的确切位置

存储(不同的行?)。


但一般来说,平均值是'sum(highs)/ len(highs)''。在Numeric中,

''sum()''的版本可以更快地运行...虽然它没有10个价格的
差异。如果你开始担心一百万的价格,

你可能会看到使用Numeric的显着提升。


我在IBM dW上有一篇关于Numerical Python的简介文章。但是

Numeric的手册开始时非常好。不过,

套餐对于简单和小型操作来说可能有点过分了。



你的,大卫...


-

mertz @ |免费信息的幽灵正在困扰着网络!所有的

gnosis |知识产权和加密暴政的权力已陷入不圣洁的状态。

..cx |联盟...想法除了他们的锁链之外没有什么可失去的。团结

|反对知识产权和反隐私制度!

------------------------------------ -------------------------------------


< blockquote> David Mertz写道:

...

但总的来说,平均值是'sum(highs)/ len(highs)''。 Numeric中版本的'sum()''的工作速度要快得多......尽管它对10个价格没有任何影响。如果你开始担心一百万的价格,
你可能会看到使用Numeric的显着提升。




不开玩笑:Numeric.sum是一个*数量级更快*为此:


[alex @ lancelot pop]


timeit.py -s''import数字''

-s''x = Numeric.array(map(float,range(1000000)))''''Numeric.sum(x)''

10循环,最好3:每循环2.11e + 04 usec

[alex @ lancelot pop]


I''m new to Python and to Numerical Python. I have a program written
in another program that used arrays extensively. I''m trying to
convert to Python.

Assume an array in Numerical Python, the contents of which are the
daily open, high, low, and last prices of the DOW Jones Industrial
Average for its entire history. How would one iterate throughout the
entire array calculating the 10 day average of daily high price or the
daily low price?

If someone could write some pseudo-code that would point me in the
right direction, I would be most appreciative.

Thanks.

解决方案

mc*****@bigfoot.com (2mc) wrote previously:
|Assume an array in Numerical Python, the contents of which are the
|daily open, high, low, and last prices of the DOW Jones Industrial
|Average for its entire history.

I''m not sure exactly where in the array the various highs and lows are
stored (different rows?).

But in general, an average is ''sum(highs)/len(highs)''. The version of
''sum()'' in Numeric will work a lot faster though... although it makes no
difference for 10 prices. If you start worrying about a million prices,
you might see a significant boost using Numeric.

I have an intro article on Numerical Python forthcoming at IBM dW. But
the manual for Numeric is quite excellent to start with. Still, the
package is probably overkill for the simple and small operations
mentioned.

Yours, David...

--
mertz@ | The specter of free information is haunting the `Net! All the
gnosis | powers of IP- and crypto-tyranny have entered into an unholy
..cx | alliance...ideas have nothing to lose but their chains. Unite
| against "intellectual property" and anti-privacy regimes!
-------------------------------------------------------------------------


David Mertz wrote:
...

But in general, an average is ''sum(highs)/len(highs)''. The version of
''sum()'' in Numeric will work a lot faster though... although it makes no
difference for 10 prices. If you start worrying about a million prices,
you might see a significant boost using Numeric.



No kidding: Numeric.sum is an *order of magnitude faster* for this:

[alex@lancelot pop]


timeit.py -s''import Numeric''
-s''x=Numeric.array(map(float,range(1000000)))'' ''Numeric.sum(x)''
10 loops, best of 3: 2.11e+04 usec per loop

[alex@lancelot pop]


这篇关于数字Python问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆