简体   繁体   中英

Julia mapslices function equivalent in Python

I'm trying to find if there's a convenient equivalent to mapslices function from the Julia language to Python. Here's the line I'm trying to convert:

line_center = float64(mapslices(x->sum(x.^4.*[1:length(x)])./sum(x.^4),no_background,1)[:])

For anyone wondering, here's an answer.

def exp_func(x):
    return np.dot(np.arange(len(x)), np.power(x, 4))/(np.sum(np.power(x, 4)))

result = np.apply_along_axis(exp_func,axis = 0,array)

exp_func takes 1-D arrays.

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