save the data in array (city*indicators*time) and give the names of each dimension
时间: 2024-09-08 19:02:22 浏览: 51
To save data with three dimensions (city, indicators, time) in an array format, you would typically use a NumPy array or a Pandas DataFrame. Here's how to do it:
Let's say you have a hypothetical dataset `data` where each row represents a city, each column an indicator, and each cell holds the value at a specific point in time. You can create a 3D array using NumPy like this:
```python
import numpy as np
# Assuming your data is already organized into lists for each dimension
cities = ["CityA", "CityB", "CityC"]
indicators = ["Indicator1", "Indicator2", "Indicator3"]
time_points = [1, 2, 3]
# Create a 3D array with cities as rows, indicators as columns, and time points as slices
data_array = np.array(data).reshape(len(cities), len(indicators), len(time_points))
# Assign names to the dimensions
dimension_names = {
0: "City",
1: "Indicators",
2: "Time"
}
data_array, dimension_names
```
The output will be a 3D array where you can access elements like `data_array['CityA', 'Indicator1', 1]` to get the value for CityA, Indicator1 at time point 1.
阅读全文