Error with np.random.suffle, result None

Asked

Viewed 53 times

0

I am trying to mix a dataset with 3 columns and then divide it in half for use of one part for training and another for ML testing. I’m using the code:

Dataset = np.append (col1, col2, axis = 1)
Dataset = np.append (Dataset, d, axis = 1)
print(Dataset)
DataRand = np.random.shuffle(Dataset)
print(DataRand)

My result:

[[-0.04772459  0.07294899 -1.        ]
 [ 0.05032483  0.06084685 -1.        ]
 [ 0.04399538 -0.23125397 -1.        ]
 ...
 [ 1.00894279  0.89593335 -1.        ]
 [ 0.92998115  0.97773105 -1.        ]
 [ 0.80732527  1.00532736 -1.        ]]
None

I expected the dataset to come with different numbers, but the result was None...why? How to correct?

1 answer

2


The function np.random.shuffle will just shuffle your dataset and returns nothing, why its variable DataRand is None. What you can do is make a copy and then shuffle the copy if you want to stay with the initial order of your dataset.

See this simple example:

import numpy as np

col = np.array([2,7,8,3,5])
col_copy = col.copy()
np.random.shuffle(col_copy)

print(col_copy)  # [5 8 2 3 7]
print(col)       # [2 7 8 3 5]
  • I created a variable called Datarand that receives the other shuffled variable. I kept the original and imagined that Datarand would receive these values... But I got it!!! It does not return anything, it does not generate data for Datarand... ok, very perceptive! :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.