简体   繁体   中英

Python applying function over each column of the array

I am trying to use the function InterpolatedUnivariateSpline as:

from scipy.interpolate import InterpolatedUnivariateSpline
A = np.array([1,2,3,4,5])
B = np.array([11,34,56,78,19])
C = np.random.normal(0, 1, (500, 30))
model = InterpolatedUnivariateSpline(A, B, k = 1)
C2 = model(C) #fails with error object too deep for desired array
C2 = model(C[:,0]) #works but is not useful as I need inter-/extra-polation for entire C

So, how do I apply the function to all elements of array C

Edit: scipy version: 0.13.2

If I understand correctly, you could just use list comprehension:

C2 = [model(i) for i in C]

It will run "model" on all elements and return the list

Upgrade your scipy to version 0.16.1 and it will work for your multi-dimensional array, ie:

C2 = model(C)

works.

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