Skip to content

TypeError: unsupported operand type(s) for +: 'int' and 'str' #21

Closed

Description

@masayas

I see the following error when running ch04/blei_lda.py

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-5511c9e27cd2> in <module>()
     37 for ti in range(model.num_topics):
     38     words = model.show_topic(ti, 64)
---> 39     tf = sum(f for f, w in words)
     40     with open('topics.txt', 'w') as output:
     41         output.write('\n'.join('{}:{}'.format(w, int(1000. * f / tf)) for f, w in words))

TypeError: unsupported operand type(s) for +: 'int' and 'str'

I think, since the frequency, f, and word, w, are the opposite on words, did you want to write w, f in words instead, as in the following?

     39     tf = sum(f for w, f in words)
     40     with open('topics.txt', 'w') as output:
     41         output.write('\n'.join('{}:{}'.format(w, int(1000. * f / tf)) for w, f in words))

Activity

  1. changed the title [-]TypeError: unsupported operand type(s) for +: 'int' and 'str' on tf[/-] [+]TypeError: unsupported operand type(s) for +: 'int' and 'str'[/+] on Mar 12, 2017
  2. luispedro commented on Jun 25, 2017

    @luispedro
    Owner

    Sorry, I had missed this bug report. Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions