h5f.create_dataset
时间: 2023-09-08 20:11:22 浏览: 52
h5f.create_dataset is a method in the h5py Python library for creating a new dataset in a HDF5 file. The method takes several parameters, including the name of the dataset, the shape of the dataset, the data type of the dataset, and optional parameters such as compression and chunking.
Here is an example usage of h5f.create_dataset:
```python
import h5py
# Create a new HDF5 file
h5f = h5py.File('example.h5', 'w')
# Create a new dataset
data = [1, 2, 3, 4, 5]
dataset = h5f.create_dataset('my_dataset', shape=(5,), dtype='i', data=data)
# Close the file
h5f.close()
```
In this example, we create a new HDF5 file using the 'w' mode. We then create a new dataset called 'my_dataset' with a shape of (5,), meaning it has 5 elements. The data type of the dataset is 'i', which means it contains integers. We also specify the data to be stored in the dataset using the 'data' parameter.
After creating the dataset, we close the file using the 'close' method. The resulting HDF5 file will contain a dataset called 'my_dataset' with the values [1, 2, 3, 4, 5].