-2

I need to get a random numpy array and each value must be with 2 decimals. I have tried something like this:

wH2 = np.random.uniform(0, 100, 2)
wH2 = np.around(wH2,2)

But around is modifying the values from the array.

ex: After around 0.7485443 will be 0.75. I need to keep it 0.74

Can someone help me?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Paul Vio
  • 57
  • 1
  • 7
  • 1
    Does this answer your question? [Truncating decimal digits numpy array of floats](https://stackoverflow.com/questions/42021972/truncating-decimal-digits-numpy-array-of-floats) – abhilb Dec 16 '19 at 15:44
  • @PaulVio Why do you need a certain number of decimals? – AMC Dec 16 '19 at 16:01
  • I have homework to create a neural network for solving XOR, and my teacher asked me to check if the number of decimals matters. – Paul Vio Dec 16 '19 at 18:03

2 Answers2

4

If it's a random array, does it really matter the precision of rounding?

In any case, try this:

wH2 = np.random.uniform(0, 100, 2)
wH2 = wH2*100//1/100
r.ook
  • 13,466
  • 2
  • 22
  • 39
0

Maybe this would work for you:

wH2 = np.fix(np.random.uniform(0, 10000, 2))/100
Alper
  • 299
  • 2
  • 12