{"id":291,"hash":"ba151c4500fe3a48d8d3e620af242b9de4fce45c05082e5aedb42a42d29c24e5","pattern":"AttributeError: &#39;Tensor&#39; object has no attribute &#39;numpy&#39;","full_message":"I downloaded this code from GitHub.\n\npredicted_id = tf.multinomial(tf.exp(predictions), num_samples=1)[0][0].numpy()\n\nBut I get an error that says:\n\nAttributeError: 'Tensor' object has no attribute 'numpy'\n\nWhat is wrong, and how do I fix it?","ecosystem":"pypi","package_name":"numpy","package_version":null,"solution":"I suspect the place where you copied the code from had eager execution enabled, i.e. had invoked tf.enable_eager_execution() at the start of the program.\n\nYou could do the same.\n\nUPDATE: Note that eager execution is enabled by default in TensorFlow 2.0. So the answer above applies only to TensorFlow 1.x","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/52357542/attributeerror-tensor-object-has-no-attribute-numpy","votes":109,"created_at":"2026-04-19T04:41:46.111866+00:00","updated_at":"2026-04-19T04:51:57.734125+00:00"}