I'm trying to use Tensorlow on İris dataset using sublime as the text editor. I got this error "TypeError: float() argument must be a string or a number, not 'generator'"when running the session, but I haven't any Idea about it. Please help me out. Attached is the error screenshot. Pl

  • $\begingroup$ try to do np.array(...).tolist() .. while generating your x1, x2 and y $\endgroup$ – Sandeep Bhutani Sep 17 '19 at 15:39

I don't know precisely what's happening under the hood, but your list comprehensions on lines 31-33 are wrong and causing numpy to produce some funky arrays.

If you pull each of them out of the np.array calls and attempt to run them, you'll generate a nice SyntaxError (which is nice because it'll loudly tell us what's wrong!). Right now, the error is getting suppressed by the fact Python is taking that funky list comprehension and creating a generator expression (I'm guessing due to how Python manages argument packing).

I'm unsure of the intent of lines 31 and 32 (are they supposed to be individual records from the data?), but line 33 can be rewritten as:

rand_y = np.array([binary_target[y_i] for y_i in rand_index])
  • $\begingroup$ Thank you, let me try on that $\endgroup$ – mayanja abu Sep 18 '19 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.