Issue
I have a list of NumPy arrays, I want to apply rot90
and flip
function randomly on it. So that in the end, I have a list where some arrays are as it is, and some are modified (with that two fuctions).
I directly pass that list of arrays to numpy.random.choice
, it gives me the following error ValueError: a must be 1-dimensional
.
thanks in advance.
Solution
One approach it to create a population of functions and pick randomly, using random.choice
, the one to apply to each image:
import random
import numpy as np
# for reproducibility
random.seed(42)
np.random.seed(42)
# toy data representing the list of images
images = [np.random.randint(255, size=(128, 128)) for _ in range(10)]
functions = [lambda x: x, np.rot90, np.flip]
# pick function at random at apply to image
res = [random.choice(functions)(image) for image in images]
Answered By - Dani Mesejo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.