0

Consider the matrix m:

let m = [ [ 1 , 2 ] , [ 3 , 4 ] ]

Apply the exponentiation function to m:

let mexp = math.exp(m)

Now JSON.stringify(mexp) outputs:

"[[2.718281828459045,7.38905609893065],[20.085536923187668,54.598150033144236]]"

So the built in exponentiation function was applied elementwise to the matrix and the result is a matrix.

Let's say I have a custom scalar function sigmoid:

let sigmoid = x => 1 / ( 1 + Math.exp(-x) )

Now I would like to apply sigmoid elementwise to the matrix as if it was a math.js built in function:

math.sigmoid(m)

How can I implement this?

4

1 回答 1

2

您可以简单地使用math.map,并自定义 sigmoid 以使用map

math.map(m, sigmoid)

更多这里http://mathjs.org/docs/reference/functions/map.html

于 2017-12-25T09:42:51.290 回答