I have a numpy array like this:
[[0. 1. 1. ... 0. 0. 1.]
[0. 0. 0. ... 0. 0. 1.]
[0. 0. 1. ... 0. 0. 0.]
...
[0. 0. 0. ... 0. 0. 1.]
[0. 0. 0. ... 0. 0. 1.]
[0. 0. 0. ... 1. 0. 1.]]
I transform it like this to reduce the memory demand:
x_val = x_val.astype(np.int)
resulting in this:
[[0 1 1 ... 0 0 1]
[0 0 0 ... 0 0 1]
[0 0 1 ... 0 0 0]
...
[0 0 0 ... 0 0 1]
[0 0 0 ... 0 0 1]
[0 0 0 ... 1 0 1]]
However, when I do this:
x_val = to_categorical(x_val)
I get:
in to_categorical
categorical = np.zeros((n, num_classes), dtype=np.float32)
MemoryError
Any ideas why? Ultimately, the numpy array contains the labels for a binary classification problem. So far, I have used it as float32
as is in a Keras ANN and it worked fine and I achieved pretty good performance. So is it actually necessary to run to_categorical
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…