Python 使用 map 命令更改数组 (numpy)
Python changing arrays (numpy) using the map command
我从文件中导入数据以制作散点图。来自 csv 文件的数据并不完全是我要绘制的,至于第二列,我希望列中先前条目的总和作为我的 y 轴。
我无法使用 map 命令从数组转换为对数据求和。当我收到错误时:
类型错误:'numpy.float64'对象不可迭代
from matplotlib import pyplot
import numpy
x,y = numpy.loadtxt ('LAX_booths_data_set_1.csv',
unpack = True,
delimiter = ',')
x2,y2 = numpy.loadtxt ('LAX_booths_data_set_2.csv',
unpack = True,
delimiter = ',')
newy = map(sum, y)
newy2 = map(sum, y2)
pyplot.plot(x,newy)
pyplot.plot(x2,newy2)
pyplot.title('Comparing Different Booth Schedules')
pyplot.ylabel('Number of Booths (Total)')
pyplot.xlabel('Time (Minutes)')
pyplot.show()
所以 map 将函数独立应用于数组的所有元素,我认为你想使用 numpy.cumsum
newy = numpy.cumsum(y)
我从文件中导入数据以制作散点图。来自 csv 文件的数据并不完全是我要绘制的,至于第二列,我希望列中先前条目的总和作为我的 y 轴。
我无法使用 map 命令从数组转换为对数据求和。当我收到错误时:
类型错误:'numpy.float64'对象不可迭代
from matplotlib import pyplot
import numpy
x,y = numpy.loadtxt ('LAX_booths_data_set_1.csv',
unpack = True,
delimiter = ',')
x2,y2 = numpy.loadtxt ('LAX_booths_data_set_2.csv',
unpack = True,
delimiter = ',')
newy = map(sum, y)
newy2 = map(sum, y2)
pyplot.plot(x,newy)
pyplot.plot(x2,newy2)
pyplot.title('Comparing Different Booth Schedules')
pyplot.ylabel('Number of Booths (Total)')
pyplot.xlabel('Time (Minutes)')
pyplot.show()
所以 map 将函数独立应用于数组的所有元素,我认为你想使用 numpy.cumsum
newy = numpy.cumsum(y)