How to create an array of "x" decimal numbers between the values "y" and "z"?

1

I want to obtain an array of decimal numbers between two values, (for example 2000.00 and 2100.00). I do not know how to do it: At the moment I have two alternatives, they never give me what I want:

import numpy as np
import random
import decimal
all_values = np.array([2000*np.random.random(3) for i in range(10)])
print all_values

gives me:

[[ 1237.71422998   858.3542556   1695.09000406]
 [  514.20215484   516.17059591  1512.52499356]
 [  744.42314666  1232.74944277  1434.53144762]
 [ 1201.13668055  1079.46214307   712.08913567]
 [  476.53854297   581.41400812  1512.70774028]
 [ 1202.66565767   209.74780245  1371.3482648 ]
 [  155.01843411   155.92438582  1149.84599247]
 [ 1866.7402305    159.65721067  1142.88608352]
 [ 1388.39461687  1677.20085145  1467.13341664]
 [ 1957.88998384  1041.01827722  1483.86465783]]

And on the other hand with:

import numpy as np
import random
import decimal
all_values = np.array([decimal.Decimal(random.randrange(200000, 210000))/100
 for i in range(3)] )
print all_values

I get only one line of three decimals:

[Decimal('2093.56') Decimal('2013.24') Decimal('2028.18')]

I do not know why we have "Decimal" and how to discard it.

In short, I want to create a file with the values of three "cryptocurrencies" for some exercises:

{"BTC":{"USD":2167.85},"ETH":{"USD":167.88},"DASH":{"USD":102.31}}
{"BTC":{"USD":2175.15},"ETH":{"USD":168.08},"DASH":{"USD":102.24}}
...
    
asked by ThePassenger 28.05.2017 в 17:38
source

1 answer

1

If I do not miss something, I think numpy.random.uniform you can come perfect:

import numpy as np

all_values = np.random.uniform(2000.00, 2100.00,[3])
print all_values

Exits example:

  

[2002.54039356, 2026.36795063, 2022.74512326]
  [2097.12514304, 2057.80636756, 2028.92052107]

The first parameter is the lower limit, the second the upper limit. All exits are greater than or equal to the lower limit and less than the upper limit .

The third parameter allows to indicate the number of elements that we want and allows to obtain matrices of any number of axes:

>>> np.random.uniform(2000.00, 2100.00,[2, 3])
array([[ 2082.64829689,  2014.76782067,  2013.11257976],
       [ 2053.63698939,  2035.80081331,  2092.53029042]])

>>> np.random.uniform(2000.00, 2100.00)
2041.0258945855817
    
answered by 28.05.2017 / 17:50
source