from keras.utils import to_categorical的逆过程
时间: 2024-05-14 17:12:11 浏览: 160
浅谈keras中的keras.utils.to_categorical用法
The inverse process of `from keras.utils import to_categorical` is `np.argmax()` function from the NumPy library. It converts the one-hot encoded arrays (created using `to_categorical()`) back into numerical labels.
Example:
```python
import numpy as np
from keras.utils import to_categorical
# Create numerical labels
labels = np.array([0, 1, 2, 1, 0, 2])
# Convert numerical labels to one-hot encoded arrays
one_hot_labels = to_categorical(labels)
# Convert one-hot encoded arrays back to numerical labels
numerical_labels = np.argmax(one_hot_labels, axis=1)
print(numerical_labels) # Output: [0 1 2 1 0 2]
```
阅读全文