Reputation: 23
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
from scipy import integrate
from scipy.optimize import fmin
Td=np.array([0.5,1,1.5,2,2.2,3,3.5,4,4.5,5])#time
findindex=lambda x:np.where(mt>=x)[0][0]
mindex=map(findindex,Td)
Zm=Td[mindex]
When I try to run this code it throws an exception.
Exception has occurred: IndexError
only integers, slices (:
), ellipsis (...
), numpy.newaxis (None
) and integer or boolean arrays are valid indices.
I am new in Python. Can someone help to solve this.
Upvotes: 0
Views: 551
Reputation: 8273
IIUC you want to filter the index meet some criteria and then slice the numpy array using those indexes
mt=3
Td[np.where(Td<mt)] # where values in Td array less than mt get indexes and slice the array
Upvotes: 1