Rap*_*pid 10 python arrays numpy mpf mpmath
我有:
import numpy as np
from mpmath import *
mpf(np.array(range(0,600)))
Run Code Online (Sandbox Code Playgroud)
但它不会让我这样做:
TypeError: cannot create mpf from array
Run Code Online (Sandbox Code Playgroud)
那我该怎么办?
基本上我将使用这个数组,并根据环境(例如1.35626567e1084
或6.2345252e-2732
)因此需要mpf ,以元素方式乘以非常大或令人难以置信的小数.
更具体地说,我将使用besseli和besselk函数创建令人难以置信的大而令人难以置信的小值.
如何获得一个mpf数组来保存这些数字?
jor*_*eca 14
将数组乘以mpf数就可以了:
import numpy as np
import mpmath as mp
small_number = mp.besseli(400, 2) # This is an mpf number
# Note that creating a list using `range` and then converting it
# to an array is not very efficient. Do this instead:
A = np.arange(600)
result = small_number * A # Array of dtype object, ie, it contains mpf numbeers
Run Code Online (Sandbox Code Playgroud)
在元素方面乘以两个包含mpf数的数组也可以工作:
result * result
Run Code Online (Sandbox Code Playgroud)
所以你真正的问题是如何评估numpy数组中的mpmath函数.要做到这一点,我会使用np.frompyfunc
(前一段时间这是唯一的选择).
besseli_vec = np.frompyfunc(mp.besseli, 2, 1)
besseli_vec(0, A)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5307 次 |
最近记录: |