小编gab*_*aiz的帖子

在Python的Fraction模块中使用numpy向量元素

我正在尝试使用numpy数组中的元素作为Fraction模块的输入,我收到以下错误:"TypeError:两个参数都应该是Rational实例"

例如,如果我这样做:

Y  =  np.array([7,1], dtype='int64')  
X  =  Y[0]*3+Y[1]
Run Code Online (Sandbox Code Playgroud)

然后:

a = Fraction(58,X)  
Run Code Online (Sandbox Code Playgroud)

我会得到同样的错误.我也尝试过 X=X.astype('int'),或者X=X.astype('int32')没有成功.

我需要做什么才能在Fraction模块所需的"Rational实例"中转换numpy数组?

python numpy fractions

5
推荐指数
1
解决办法
1032
查看次数

标签 统计

fractions ×1

numpy ×1

python ×1