简体   繁体   中英

How to subtract symbolic value from list and get log value

I have to subtract symbolic value from a list and get log value of that. This will return corresponding symbolic expressions as a list. That expression should be element vice operation.

I have tried this using numpy and sympy in different ways. But without using loops, I couldn't find a solution.

import sympy as sp
u = sp.symbols('u', real=False)
a = [1, 2, 3, 5]
answer = sp.log(u - a)

TypeError: unsupported operand type(s) for -: 'Symbol' and 'list'

I assume what you want as an output is: [log(u - 1), log(u - 2), log(u - 3), log(u - 5)]

With Loop:

import sympy as sp
a = [1, 2, 3, 5]
[sp.log(u - x) for x in a]

Without Loop:

import sympy as sp
u = sp.symbols('u', real=False)
a = [1, 2, 3, 5]
answer = list(map(lambda x: sp.log(u - x), a))
answer

Hope this helps :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM