Question
Please help me with this question: There's an error when I run this code, it tells me:IndexError: too many indices for array: array is 1-dimensional,
Please help me with this question:
There's an error when I run this code, it tells me:IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed.
How can I solve it? My code: import numpy as np data = np.genfromtxt('data_temperature.txt', delimiter=',', dtype=None, encoding=None, skip_header=1) #data = np.loadtxt('data_temperature.txt', delimiter=',', usecols =[0,1,2,3,4,5,6,7], skiprows = 1)
#Task 2 #Pre-Todos et todas-Avant tout: def filter_by_city(data, city_name): return data[data[:, 1] == city_name.encode()]
Btw, the data type is
Date,Location,Max Temperature (C),Min Temperature (C),Precipitation (mm),Wind Speed (km/h),Humidity (%),Cloud Cover (%)
2023-01-01,New York,5,-2,10,20,70,40
2023-01-02,New York,4,-3,8,18,75,30 for 10 cities
#Group Project #Task 1 import numpy as np data = np.genfromtxt('data_temperature.txt', delimiter=',', dtype=None, encoding=None, skip_header=1) #data = np.loadtxt('data_temperature.txt', delimiter=',', usecols =[0,1,2,3,4,5,6,7], skiprows = 1) #Task 2 #Pre-Todos et todas-Avant tout: def filter_by_city(data, city_name): return data[data[:, 1] == city_name.encode()] New_York_data = filter_by_city(data, 'New York') Los_Angeles_data = filter_by_city(data, 'Los Angeles') London_data = filter_by_city(data, 'London') Tokyo_data = filter_by_city(data, 'Tokyo') Beijing_data = filter_by_city(data, 'Beijing') Sydney_data = filter_by_city(data, 'Sydney') Paris_data = filter_by_city(data, 'Paris') Berlin_data = filter_by_city(data, 'Berlin') Cairo_data = filter_by_city(data, 'Cairo') New_Delhi_data = filter_by_city(data, 'New Delhi')
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started