【发布时间】:2019-11-19 02:33:19
【问题描述】:
我是 matploblib 和 numpy 的新手,在尝试提取数据时遇到了问题。以下代码导致 IndexError: boolean index did not match indexed array along dimension 0;维度是 32,但对应的布尔维度是 112。请告知!
使用的数据集:https://data.gov.sg/dataset/monthly-motor-vehicle-population-by-type-of-fuel-used
import numpy as np
import matplotlib.pyplot as plt
title = "motor-vehicle-population-statistics-by-type-of-fuel-used."
titlelen = len(title)
print("{:*^{titlelen}}".format(title, titlelen=titlelen+6))
print()
data = np.genfromtxt("data/motor-vehicle-population-statistics-by-type-of-fuel-used.csv",
dtype=("datetime64[Y]","U100","U110",int),
delimiter=",",
names=True)
years = np.unique(data["month"])
category = np.unique(data['category'])
type = np.unique(data['type'])
cars = data[data["category"]=="Cars"]["number"]
carspetrol = cars[data["type"]=="Petrol"]["number"]
# print(cars)
print(carspetrol)
【问题讨论】: