Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Element-wise operations in mpmath

Tags:

python

mpmath

I am looking to perform element-wise mpmath operations on Python arrays. For example,

import mpmath as mpm
x = mpm.arange(0,4)
y = mpm.sin(x)        # error

Alternatively, using mpmath matrices

x = mpm.matrix([0,1,2,3])
y = mpm.sin(x)             # error

Does mpmath have any capibilities in this area, or is it necessary to loop through the entries?

like image 659
Doubt Avatar asked Mar 16 '13 14:03

Doubt


1 Answers

mpmath does not appear to handle element-wise operation, but you can use numpy to get this functionality:

import numpy as np
import mpmath as mpm
x = np.array(mpm.arange(0,4))

sin = np.vectorize(mpm.sin)
y = sin(x)
like image 157
DrRobotNinja Avatar answered Sep 19 '22 23:09

DrRobotNinja