mercredi 29 juin 2022

Am tryin to generate different values for each element of a column of a numpy array using a certain range for each column but it's not abiding by it

I need each column to generate random integers with specified range for col 1 (random.randint(1, 50) for col 2 random.randint(51, 100)...etc

import numpy
import random
import pandas
from random import randint
wsn = numpy.arange(1, 6)
taskn = 3

t1 = numpy.random.randint((random.randint(2, 50),random.randint(51, 100),
    random.randint(101, 150),random.randint(151, 200),random.randint(201, 250)),size=(5,5))
t2 = numpy.random.randint((random.randint(2, 50),random.randint(51, 100),
    random.randint(101, 150),random.randint(151, 200),random.randint(201, 250)),size=(5,5))
t3= numpy.random.randint((random.randint(2, 50),random.randint(51, 100),
    random.randint(101, 150),random.randint(151, 200),random.randint(201, 250)),size=(5,5))
print('\nGenerated Data:\t\n\nNumber   \t\t\t Task 1 \t\t\t Task 2 \t\t\t Task 3\n')
ni = len(t1)
for i in range(ni):
    print('\t {0}    \t   {1}   \t {2} \t {3}\n'.format(wsn[i], t1[i],t2[i],t3[i]))
print('\n\n')

It prints the following

   Generated Data:  

Number               Task 1              Task 2              Task 3

     1         [  1  13  16 121  18]     [  5  22  34  65 194]   [ 10  68  60 134 130]

     2         [  0   2 117 176  46]     [  1  15 111 116 180]   [22 41 70 24 85]

     3         [  0  12 121  19 193]     [  0   5  37 109 205]   [  5  53   5 106  15]

     4         [  0   5  97  99 235]     [  0  22 142  11 150]   [  6  79 129  64  87]

     5         [  2  46  71 101 186]     [  3  57 141  37  71]   [ 15  32   9 117  77]

soemtimes It even generates 0 when I didn't even specifiy 0 in the ranges




Aucun commentaire:

Enregistrer un commentaire