jeudi 24 septembre 2020

How to randomly change the signs of some of the elements in a numpy array?

Given a numpy array

import numpy as np
from numpy.random import random
N = 5
x = random(N)

How to randomly multiply a subset of (some of the elements in) x by -1 in order to change the sign of some of the elements in the array?




Aucun commentaire:

Enregistrer un commentaire