将数组乘以mpf数即可:
import numpy as npimport mpmath as mpsmall_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
逐个将包含mpf数字的两个元素数组相乘也可以:
result * result
因此,您真正的问题是如何在numpy数组中评估mpmath函数。为此,我会使用
np.frompyfunc(前一段时间这是唯一的选择)。
besseli_vec = np.frompyfunc(mp.besseli, 2, 1)besseli_vec(0, A)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)