为什么没有arg,对于comlex类型的abs方法? [英] why no arg, abs methods for comlex type?

查看:50
本文介绍了为什么没有arg,对于comlex类型的abs方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我经常需要处理复数

使用python iteractive作为计算器


我想知道为什么没有类似arg,abs


的方法可以使用

c = 1 + 1j

abs( c)


在我看来,将

的可能性写成

c.abs也很好( )

它看起来更多OO


遗憾的是没有arg方法来获得角度

的复数

当然很容易自己写一个

(这就是我为自己所做的)

但不同的人会创造和重新创造轮子

一遍又一遍

在阅读外星人代码时需要花费2秒

记住功能名称等


考虑

c = 1 + 1j

c.arg(angle_mode = cmath.GRAD) - > 45.0



c.arg(angle_mode = cmath.RAD) - > 0.7853 ..


我还想看一些更多的函数来进行

计算复数更方便

例如

c = 27

c.pow(分子= 1,分母= 3,

mode = cmath.EULER,angle_mode = cmath.GRAD)

- > ((3,0),(3,120),(3,240))


您如何看待它?

也许存在一些旨在实现这一目标的提案?


-

Daniel

Hello all,

I often have to deal with complex numbers
using python iteractive as calculator

I wonder why there are no methods like arg, abs

well one can use
c = 1+1j
abs(c)

In my opinion it would also be nice to have the
possibility to write it as
c.abs()
it looks more OO

unfortunately there is no arg method to get the angle
of the complex number
of course it easy to write one on your own
(that''s what I have done for myself)
but differnt people will create and reinvite the wheel
over and over again
while reading alien code one will have to spend 2 seconds
remembering the function names etc

consider
c = 1+1j
c.arg(angle_mode = cmath.GRAD) -> 45.0
or
c.arg(angle_mode = cmath.RAD) -> 0.7853..

I would also like to see some more functions to make
calculations with complex number more convenient
e.g.
c = 27
c.pow(numerator = 1, denominator = 3,
mode = cmath.EULER, angle_mode = cmath.GRAD)
-> ((3,0), (3,120), (3,240))

what do you think about it?
maybe there exists some proposals aiming this goal?

--
Daniel

推荐答案

>我还想看一些更多的函数来使
> I would also like to see some more functions to make
计算复杂数字更方便
例如
c = 27
calculations with complex number more convenient
e.g.
c = 27




c = 27 + 0j



c = 27+0j




"DanielSchüle" < UV ** @ rz.uni-karlsruhe.de>在消息中写道

news:dc ********** @ news2.rz.uni-karlsruhe.de ...

"Daniel Schüle" <uv**@rz.uni-karlsruhe.de> wrote in message
news:dc**********@news2.rz.uni-karlsruhe.de...
我想知道为什么会有没有方法像arg,abs
一个人可以使用
c = 1 + 1j
abs(c)

在我看来这样做也很好
可能把它写成
c.abs()
它看起来更多OO


Python是基于对象的,但在语法或外观上并不是严格的OO 。这是一个

故意设计决定。不是多余的是多余的。

遗憾的是没有arg方法来获得复数的角度。


我同意这是缺陷。我认为.angle()应该是一个

无参数方法,比如.conjugate(),虽然它的内部实现将需要访问相应的cmath函数。
需要访问相应的cmath函数。我认为返回弧度

可能就足够了。如果不是补丁,您可以向SourceForge跟踪器提交RFE

(请求增强)。

我还希望看到更多功能来制作
复数更方便的计算
c = 27
c.pow(分子= 1,分母= 3,
模式= cmath.EULER,angle_mode = cmath.GRAD)
- > ((3,0),(3,120),(3,240))


想要所有的根都是相当专业的。 sqrt(4)是2,而不是(2,-2)。

您如何看待它?
可能存在一些旨在实现这一目标的提案?
I wonder why there are no methods like arg, abs well one can use
c = 1+1j
abs(c)

In my opinion it would also be nice to have the
possibility to write it as
c.abs()
it looks more OO
Python is object based but not rigidly OO in syntax or looks. This is an
intentional design decision. Not being gratuitiously redundant is another.
unfortunately there is no arg method to get the angle
of the complex number
I agree that this is a deficiency. I would think .angle() should be a
no-param method like .conjugate(), though its internal implementation would
need access to the appropriate cmath functions. I think returning radians
might be enough though. You could submit to the SourceForge tracker a RFE
(Request For Enhancement) if not a patch.
I would also like to see some more functions to make
calculations with complex number more convenient
e.g.
c = 27
c.pow(numerator = 1, denominator = 3,
mode = cmath.EULER, angle_mode = cmath.GRAD)
-> ((3,0), (3,120), (3,240))
Wanting all roots is fairly specialized. sqrt(4) is 2, not (2, -2).
what do you think about it?
maybe there exists some proposals aiming this goal?



您是否在numpy,numarray,scipy或

类似的软件包中寻找复杂的数学函数?用Python编写的cmath2模块可能是有用的。


Terry J. Reedy




Have you looked for complex math functions in numpy, numarray, scipy or
similar packages? It is possible that a cmath2 module, written in Python,
could be useful.

Terry J. Reedy



2005年8月5日星期五15:42:41 +0200,

Daniel Sch ?? le< uv ** @ rz.uni- karlsruhe.de>写道:
On Fri, 05 Aug 2005 15:42:41 +0200,
Daniel Sch??le <uv**@rz.uni-karlsruhe.de> wrote:
大家好,
我经常要处理复杂的数字
使用python iteractive作为计算器
我想知道为什么没有类似的方法arg,abs
一个人可以使用
c = 1 + 1j
abs(c)
在我看来,有可能写的可能性很好它就像
c.abs()
它看起来更多OO


我想这也是出于同样的原因我们不能饶恕

写这样的东西:


z = x.squared()。added_to(y.squared())。squareroot()

E = m.multiplied_by(c.squared())


更多OO,是的。更具可读性,而不是IMO。

我还想看一些更多的功能来进行复杂数字的计算更方便


[.. 。]

也许存在一些针对这个目标的建议?
Hello all,
I often have to deal with complex numbers
using python iteractive as calculator I wonder why there are no methods like arg, abs well one can use
c = 1+1j
abs(c) In my opinion it would also be nice to have the
possibility to write it as
c.abs()
it looks more OO
I guess it''s for the same reason that we are spared
from writing things like this:

z = x.squared().added_to(y.squared()).squareroot()
E = m.multiplied_by(c.squared())

More OO, yes. More readable, not IMO.
I would also like to see some more functions to make
calculations with complex number more convenient
[ ... ]
maybe there exists some proposals aiming this goal?




SciPy或Numeric?


问候,

Dan


-

Dan Sommers

< http:// www.tombstonezero.net/dan/>



SciPy or Numeric?

Regards,
Dan

--
Dan Sommers
<http://www.tombstonezero.net/dan/>


这篇关于为什么没有arg,对于comlex类型的abs方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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