【问题标题】:Python only integers, slices ... and integer or boolean arrays are valid indicesPython 只有整数、切片...和整数或布尔数组是有效的索引
【发布时间】:2018-12-04 14:09:51
【问题描述】:
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]

当我尝试运行此代码时,它会引发异常。

发生异常:IndexError 只有整数、切片 (:)、省略号 (...)、numpy.newaxis (None) 和整数或布尔数组是有效的索引。

我是 Python 新手。 有人可以帮忙解决这个问题吗?

【问题讨论】:

  • 你想达到什么目的?mt是什么?

标签: python


【解决方案1】:

IIUC 您要过滤的索引满足某些条件,然后使用这些索引对 numpy 数组进行切片

mt=3
Td[np.where(Td<mt)] # where values in Td array less than mt get indexes and slice the array

【讨论】:

    猜你喜欢
    • 2021-08-29
    • 1970-01-01
    • 2016-04-29
    • 2018-03-11
    • 1970-01-01
    • 1970-01-01
    • 2017-12-08
    • 2019-03-13
    • 2017-11-24
    相关资源
    最近更新 更多