1

Hello people of StackExchange,

I'm using the library mpmath for a project and I need some help with arrays, namely, passing them through functions.

I have no problem creating an array with mpf elements. This code excerpt lets me do just that:

(...)

ds = 0.001

str_ds = str(ds); ds = mpf(str_ds)

s1 = arange(pi/mpf('2.0'), (3.0/2.0) * pi + ds/mpf('2.0'), ds)  
s2 = arange(pi/mpf('2.0'),-(1.0/2.0) * pi - ds/mpf('2.0'),-ds)

s1 = array(s1)
s2 = array(s2)

def r1(s):
    return array([xc + r * cos(s), r * sin(s)])

def r2(s):
    return array([xc + L + r * cos(s), r * sin(s)])

However, if I call in the next lines:

r1 = r1(s1)

r2 = r2(s2)

It gives me an error. Is there any way to pass an array with mpf elements through a function?

EDIT: I've tried using vectorize inside each r1 and r2 functions like so:

cos = vectorize(cos)
sin = vectorize(sin)

But it keeps not working.

0 Answers0