{"action":"created","issue":{"url":"https://api.github.com/repos/tensorflow/tensorflow/issues/1482","repository_url":"https://api.github.com/repos/tensorflow/tensorflow","labels_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/1482/labels{/name}","comments_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/1482/comments","events_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/1482/events","html_url":"https://github.com/tensorflow/tensorflow/issues/1482","id":140500334,"number":1482,"title":"getting the dynamic shape of a Tensor as an integer","user":{"login":"daksunt","id":4890903,"avatar_url":"https://avatars.githubusercontent.com/u/4890903?v=3","gravatar_id":"","url":"https://api.github.com/users/daksunt","html_url":"https://github.com/daksunt","followers_url":"https://api.github.com/users/daksunt/followers","following_url":"https://api.github.com/users/daksunt/following{/other_user}","gists_url":"https://api.github.com/users/daksunt/gists{/gist_id}","starred_url":"https://api.github.com/users/daksunt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daksunt/subscriptions","organizations_url":"https://api.github.com/users/daksunt/orgs","repos_url":"https://api.github.com/users/daksunt/repos","events_url":"https://api.github.com/users/daksunt/events{/privacy}","received_events_url":"https://api.github.com/users/daksunt/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-03-13T16:05:15Z","updated_at":"2016-03-13T18:24:09Z","closed_at":null,"body":"How can I get xshape as a int variable? Is this feature available?\r\n\r\nOf course if I evaluate, I will get the value of xshape, but the input is dynamic and I don't want to use the get_sum function in for loop, because it would break the graph.\r\n\r\nProblem: TypeError: range() integer end argument expected, got Tensor\r\n\r\n```\r\nimport tensorflow as tf\r\nimport numpy as np\r\n\r\n\r\nx = tf.placeholder(tf.float32, shape=[None])\r\nxshape = tf.placeholder(tf.float32, shape=[])\r\n\r\n\r\ndef get_sum(x, xshape):\r\n  sum = 0\r\n  for i in range(xshape):\r\n    sum += x[i]\r\n\r\ninit = tf.initialize_all_variables()\r\nsum = get_sum(x, xshape)\r\n\r\nwith tf.Session() as sess:\r\n  sess.run(init)\r\n  for i in range(100):\r\n    length = np.random.randint(0,10)\r\n    a = np.random.randint(0, 10, length)\r\n  print sess.run(sum,feed_dict={x:a, xshape:length})\r\n```"},"comment":{"url":"https://api.github.com/repos/tensorflow/tensorflow/issues/comments/196015986","html_url":"https://github.com/tensorflow/tensorflow/issues/1482#issuecomment-196015986","issue_url":"https://api.github.com/repos/tensorflow/tensorflow/issues/1482","id":196015986,"user":{"login":"daksunt","id":4890903,"avatar_url":"https://avatars.githubusercontent.com/u/4890903?v=3","gravatar_id":"","url":"https://api.github.com/users/daksunt","html_url":"https://github.com/daksunt","followers_url":"https://api.github.com/users/daksunt/followers","following_url":"https://api.github.com/users/daksunt/following{/other_user}","gists_url":"https://api.github.com/users/daksunt/gists{/gist_id}","starred_url":"https://api.github.com/users/daksunt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daksunt/subscriptions","organizations_url":"https://api.github.com/users/daksunt/orgs","repos_url":"https://api.github.com/users/daksunt/repos","events_url":"https://api.github.com/users/daksunt/events{/privacy}","received_events_url":"https://api.github.com/users/daksunt/received_events","type":"User","site_admin":false},"created_at":"2016-03-13T18:24:09Z","updated_at":"2016-03-13T18:24:09Z","body":"I want to do process on variable length tensors. In other words I need to do a computation for each element in a tensor with different values. Getting the shape as an integer is a first step."}}