Cannot create mpf from array

68 Views Asked by At

I am not fluent in Python.

I have this code:

import numpy as np
import pyvista as pv
from mpmath import hyp2f1, gamma, re, exp

k = 5
n = (k - 1)/k
rho = 1.0/np.sqrt(4**n * gamma((3 - n)/2) * gamma(1 + n/2)/(gamma((3 + n)/2)*gamma(1 - n/2)))

def phi(n, z):
    return z**(1 + n)*hyp2f1((1 + n)/2, n, (3 + n)/2, z**2)/(1 + n)

def f(r, t):
    z = r * exp(1j*t)
    return np.array([
        float(re(0.5*(phi(n, z)/rho - rho*phi(-n, z)))),
        float(re(0.5j * (rho*phi(-n, z) + phi(n, z)/rho))),
        float(re(z))
    ])

When I run f(1, 1), it works fine. But when I do

r_ = np.linspace(0, 2, 50) 
t_ = np.linspace(1e-6, 2*np.pi, 50)
r, t = np.meshgrid(r_, t_)
x, y, z = f(r, t)

then I get the error Cannot create mpf from array. What's wrong?

0

There are 0 best solutions below