我有一个看起来像这样的数组:
k = numpy.array([(1.,0.001), (1.1, 0.002), (None, None),
(1.2, 0.003), (0.99, 0.004)])
我想绘制不是的值(None, None)
并保留数组值的索引。也就是说,我想要一个(None, None)
有价值的地方。
完成后,我想绘制
y = k[:,0] + k[:,1]
但我什至不能将数组加在一起。k
我尝试屏蔽数组,但我丢失了原始数组的索引值。
一个最小的例子:
import matplotlib.pyplot as pyplot
import numpy
x = range(5)
k = numpy.array([(1.,0.001), (1.1, 0.002), (None, None),
(1.2, 0.003), (0.99, 0.004)])
Fig, ax = pyplot.subplots()
# This plots a gap---as desired
ax.plot(x, k[:,0], 'k-')
# I'd like to plot
# k[:,0] + k[:,1]
# but I can't add None
# Here I get rid of the (None, None) values so I can add
# But I lose the original indexing
mask = k != (None, None)
y = k[mask].reshape((-1,2))
ax.plot(range(len(y)), y[:,0]+y[:,1], 'k--')