Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

states array of data type np.ndarray causes an error when trying to find index of values #16

Open
dr-aheydari opened this issue Nov 3, 2022 · 2 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request
Milestone

Comments

@dr-aheydari
Copy link

dr-aheydari commented Nov 3, 2022

Description

The current code for simulating a random walk cannot handle data type np.array as the states vector, given that numpy arrays do not have index attribute.

Steps/Code to Reproduce

With the current code base, the issue can be reproduced using the following:

from pyrandwalk import *
import numpy as np

# Using the same examples given in README for transition matrix
trans = np.array([[1,    0, 0,    0, 0], [0.25, 0, 0.75, 0, 0],[0, 0.25, 0, 0.75, 0], [0, 0, 0.25, 0, 0.75], [0, 0,    0, 1,    0]])
# The only change here is to switch `states` from a List to np.array
states =np.array([0,1,2,3,4])
# This is the check that is run using a utility to ensure the correct data types are used for states
print(isinstance(states, (list, np.ndarray)))
# >>> True
rw = RandomWalk(states, trans)
states, probs = rw.run()
# Error: `AttributeError: 'numpy.ndarray' object has no attribute 'index'`

Operating System

Linux

Python Version

Python 3.9.12

pyrandwalk Version

1.1

I will try to do a PR later to handle this issue by using np.where when we have a numpy array.

@sadrasabouri
Copy link
Owner

That's great. After merging #18 you are more than welcome to work on this new feature. Don't forget to add tests for it, too. 💯

@sadrasabouri
Copy link
Owner

You can now open your PR to dev branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants