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

2.2 Readability VS Speed #87

Open
shashikiran-alloli opened this issue Sep 18, 2019 · 1 comment
Open

2.2 Readability VS Speed #87

shashikiran-alloli opened this issue Sep 18, 2019 · 1 comment

Comments

@shashikiran-alloli
Copy link

I'm facing issues with the below code -

def function_2(seq, sub):
    target = np.dot(sub, sub)
    candidates = np.where(np.correlate(seq, sub, mode='valid') == target)[0]
    check = candidates[:, np.newaxis] + np.arange(len(sub))
    mask = np.all((np.take(seq, check) == sub), axis=-1)
    return candidates[mask]

function_2('shasdefiran','def')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-69-3a3e84d6ff06> in <module>
----> 1 function_2('shasdefiran','def')

<ipython-input-64-dc47768a25a7> in function_2(seq, sub)
      1 def function_2(seq, sub):
----> 2     target = np.dot(sub, sub)
      3     candidates = np.where(np.correlate(seq, sub, mode='valid') == target)[0]
      4     check = candidates[:, np.newaxis] + np.arange(len(sub))
      5     mask = np.all((np.take(seq, check) == sub), axis=-1)

TypeError: ufunc 'multiply' did not contain a loop with signature matching types dtype('<U3') dtype('<U3') dtype('<U3')

Please help me understand the issue with the above code.

@rougier
Copy link
Owner

rougier commented Sep 22, 2019

Can you test only the np.dot(sub,sub) call ? (and give here how do you generate the sub)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants