Skip to content

Instantly share code, notes, and snippets.

@CharlesAverill
Created April 29, 2020 01:44
Show Gist options
  • Save CharlesAverill/4c51dfd3bb3d858d6361dab44ba93626 to your computer and use it in GitHub Desktop.
Save CharlesAverill/4c51dfd3bb3d858d6361dab44ba93626 to your computer and use it in GitHub Desktop.
matrix_shape = matrix.shape
flat_matrix = matrix.flatten()
ls_matrix = flat_matrix.tolist()
num_items = len(ls_matrix)
for stricken in range(int(num_items * self.v_ratio)):
if self.value:
ls_matrix[random.randint(0, len(ls_matrix) - 1)] = self.value
else:
ls_matrix[random.randint(0, len(ls_matrix) - 1)] = random.uniform(self.low_bound, self.high_bound)
matrix = np.array(ls_matrix)
matrix = np.reshape(matrix, matrix_shape)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment