I would like to have a numpy matrix that is filled with unique objects. Currently I am creating a list of list and then converting it to a numpy array (see code below, under workaround). I am using it because I want to use slicing to access elements in the matrix
I was wondering if there was a better way to create such a matrix.
import random
import numpy as np
class RandomCell(object):
def __init__(self):
self.value = random.randint(0, 10)
def __repr__(self):
return str(self.value)
# workaround
temp_matrix = [[RandomCell() for row in range(3)] for col in range(3)]
workaround_matrix = np.array(temp_matrix)
EDIT: I want to create a matrix of objects not generate a matrix of random numbers