In python sympy, how do I apply an external python funtion to each element of the sympy matrix?
By : mygodccl
Date : March 29 2020, 07:55 AM
hop of those help? To be more specific, I want to apply the following sigmoid function: code :
>>> M.applyfunc(sigmoid)
Matrix([
[1/(exp(1) + 1), 1/(exp(3) + 1)],
[1/(exp(2) + 1), 1/(exp(4) + 1)]])
class sigmoid(Function):
pass
>>> M.applyfunc(sigmoid)
Matrix([
[sigmoid(1), sigmoid(3)],
[sigmoid(2), sigmoid(4)]])

sympy nsolve typeError with Matrix starting vector
By : user1507283
Date : March 29 2020, 07:55 AM
it helps some times The workaround you have is necessary, given the following: nsolve passes the x0 argument directly to mpmath.findroot, on this line findroot only supports iterables in x0 that satisfy isinstance(x0, (list, tuple)), on this line. Moreover it has to be a flat tuple or list; its elements are assumed to be scalars in the subsequent x0 = [ctx.convert(x) for x in x0].

Can sympy simplify block matrix expressions?
By : user1655866
Date : March 29 2020, 07:55 AM
Any of those help Yes, using the function block_collapse which evaluates blockmatrix expressions down to the level of blocks. code :
sy.block_collapse(A.inverse()*M)

Access different blocks (submatrices) of a symbolic block matrix in SymPy
By : user1733969
Date : March 29 2020, 07:55 AM
seems to work fine The (i, j) block of a block matrix C is accessed with C.blocks[i, j]. An example: code :
from sympy import *
b = Matrix([1, 2, 4, 8])
C = BlockMatrix([[b, 3*b], [5*b, 7*b]])
print(C.blocks[0, 1])

creating a block band diagonal matrix in sympy
By : Bas Wesselink
Date : March 29 2020, 07:55 AM
it helps some times I would like to create a block band diagonal matrix using sympy. Basically, the matrix should look like , The recently added banded might be a solution for you: code :
>>> size=3
>>> var('d n r')
(d, n, r)
>>> banded(size,{0:d,1:n,1:r})
Matrix([
[d, n, 0],
[r, d, n],
[0, r, d]])
>>> banded(2*size, {0:D,2:N,2:R})
Matrix([
[ a, b  I*c, e, I*f, 0, 0],
[b + I*c, d, g, I*h, 0, 0],
[ e, g, a, b  I*c, e, I*f],
[ I*f, I*h, b + I*c, d, g, I*h],
[ 0, 0, e, g, a, b  I*c],
[ 0, 0, I*f, I*h, b + I*c, d]])

