Skip to content

Commit

Permalink
Merge pull request #33 from autonomio/fix_array_shuffle
Browse files Browse the repository at this point in the history
fix array_random_shuffle
  • Loading branch information
mikkokotila authored Apr 17, 2022
2 parents ed09da3 + 7dc5520 commit 082b84d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
URL = 'http://autonom.io'
LICENSE = 'MIT'
DOWNLOAD_URL = 'https://github.com/autonomio/wrangle/'
VERSION = '0.7'
VERSION = '0.7.1'

try:
from setuptools import setup
Expand Down
2 changes: 1 addition & 1 deletion test_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
_null = wr.col_to_split(df.head(10), 'top_downstream', sep='.')

# test all the attributes starting with array_
_null = wr.array_random_shuffle(df.bouncerate1, df.bouncerate2)
_null = wr.array_random_shuffle(df[['bouncerate1', 'bouncerate2']].values, df.bouncerate2)
_null = wr.array_random_weighted(df.bouncerate1.head(10), 'normal', 10)
_null = wr.array_reshape_conv1d(df.values)
_null = wr.array_reshape_lstm(df.bouncerate1, 10, 10)
Expand Down
43 changes: 32 additions & 11 deletions wrangle/array/array_random_shuffle.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
def array_random_shuffle(x, y=None, multi_input=False):

'''Shuffles single or multi-input data. Note that
only x can be multi-input.
only x can be multi-input and x has to be more than one
column of data.
x | array or list | the x data to be shuffled
y | array | the y data to be shuffled (optional)
multi_input | bool | set to True if multi-input model data
'''

import numpy as np
Expand All @@ -22,25 +22,46 @@ def array_random_shuffle(x, y=None, multi_input=False):
# data input is list and multi_input is set to True
elif isinstance(x, list) and multi_input == True:

out = []
x_out = []

for ar in x:

rng.bit_generator.state = state
rng.shuffle(ar)
rng.shuffle(ar, axis=1)
x_out.append(ar)

rng.bit_generator.state = state
rng.shuffle(y)
x = x_out

if y is not None:
rng.bit_generator.state = state

try:
y.shape[1]
rng.shuffle(y, axis=1)
except IndexError:
rng.shuffle(y)

return x, y
return x, y

else:
return x

# data input is assumably an array (not multi-input)
elif isinstance(x, list) == False:

rng.bit_generator.state = state
rng.shuffle(x)
rng.shuffle(x, axis=1)

rng.bit_generator.state = state
rng.shuffle(y)
if y is not None:
rng.bit_generator.state = state

try:
y.shape[1]
rng.shuffle(y, axis=1)
except IndexError:
rng.shuffle(y)

return x, y

return x, y
else:
return x

0 comments on commit 082b84d

Please sign in to comment.