python数组基本用法:step函数

python数组基本用法:step函数,python,arrays,Python,Arrays,我是python的初学者,对数组或列表的用法相当困惑。请帮助我了解以下基本用法,我只想将数据分成两部分,但我不知道如何: # -*- coding: utf-8 -* import numpy as np import matplotlib.pyplot as plt import matplotlib as mpl import math from pylab import * i = np.arange(2,5,0.1) t = 1+i Light = 10 if t > 3 :

我是python的初学者,对数组或列表的用法相当困惑。请帮助我了解以下基本用法,我只想将数据分成两部分,但我不知道如何:

# -*- coding: utf-8 -*
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import math
from pylab import *

i = np.arange(2,5,0.1)
t = 1+i
Light = 10
if  t > 3 :
  Light = 5

plt.figure('God Bless: Lightcure')
plt.plot(i,Light)
plt.show()
但这不起作用,回溯如下:

Traceback (most recent call last):
File "1.py", line 11, in <module>
if  t> 3 :
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

谢谢大家! 3要做什么呢?BTW你应该考虑是的,我真的想要一个阶梯函数!user3100115:仅供参考,您添加的标签已被另一个用户回滚-这样可以吗?我觉得这不太合适,但我不知道这些技术。也许这只是一个数组问题,所以它不需要它们?@halfer我添加了标签,因为这是一个numpy | matplotlib问题,所以它不好。但是这个问题已经离题了,现在已经结束了,我当然不想通过编辑它把它发送到重新开放的投票队列。太好了!谢谢,恐怕我不知道怎么提问。还是向你学点东西,非常感谢!
# True is where condition is satisfied: numpy.ndarray([False, False, ..., True, True])
mask = t > 3

# Uninitialized array with same shape as t
Light = numpy.empty_like(t)

# Light elements set to 5 where corresponding mask elements are True
Light[mask] = 5

# Light elements set to 10 where corresponding mask elements are False
Light[~mask] = 10