我有:
import numpy as np
from mpmath import *
mpf(np.array(range(0,600)))但它不让我这么做:
TypeError: cannot create mpf from array那么我应该做些什么呢?
基本上,我将使用这个数组,并根据环境(例如1.35626567e1084或6.2345252e-2732)以令人难以置信的大小乘以元素,因此需要mpf。
更具体地说,我将使用besseli和besselk函数,它们创建令人难以置信的大值和小值。
如何让mpf数组保存这些数字?
发布于 2012-12-07 01:06:55
将一个数组乘以一个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对包含mpf数字的两个数组进行逐个元素相乘也是可行的:
result * result因此,您真正的问题是如何计算numpy数组中的mpmath函数。要做到这一点,我会使用np.frompyfunc (不久前这是唯一的选择)。
besseli_vec = np.frompyfunc(mp.besseli, 2, 1)
besseli_vec(0, A)发布于 2012-12-06 21:28:56
查看mpmath.arange:
import numpy as np
import mpmath as mp
np.array(mp.arange(600))https://stackoverflow.com/questions/13743785
复制相似问题