title: TensorFlow strings: what they are and how to work with them
body: <p>When I read file with <code>tf.read_file</code> I get something with type <code>tf.string</code>. Documentation says only that it is "Variable length byte arrays. Each element of a Tensor is a byte array." (<a href="https://www.tensorflow.org/versions/r0.10/resources/dims_types.html" rel="noreferrer">https://www.tensorflow.org/versions/r0.10/resources/dims_types.html</a>). I have no idea how to interpret this.</p>
  
  <p>I can do nothing with this type. In usual python you can get elements by index like <code>my_string[:4]</code>, but when I run following code I get an error.</p>
  
  <pre><code>import tensorflow as tf
  import numpy as np
  
  x = tf.constant("This is string")
  y = x[:4]
  
  
  init = tf.initialize_all_variables()
  sess = tf.Session()
  sess.run(init)
  result = sess.run(y)
  print result
  </code></pre>
  
  <p>It says </p>
  
  <pre>  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/tensor_shape.py", line 621, in assert_has_rank
      raise ValueError("Shape %s must have rank %d" % (self, rank))
  ValueError: Shape () must have rank 1
  </pre>
  
  <p>Also I cannot convert my string to <code>tf.float32</code> tensor. It is <code>.flo</code> file and it has magic header "PIEH". This numpy code successfuly convert such header into number (see example here <a href="https://stackoverflow.com/a/28016469/4744283">https://stackoverflow.com/a/28016469/4744283</a>) but I can't do that with tensorflow. I tried <code>tf.string_to_number(string, out_type=tf.float32)</code> but it says </p>
  
  <pre>tensorflow.python.framework.errors.InvalidArgumentError: StringToNumberOp could not correctly convert string: PIEH
  </pre>
  
  <p>So, what string is? What it's shape is? How can I at least get part of the string? I suppose that if I can get part of it I can just skip "PIEH" part.</p>
  
  <p><strong>UPD</strong>: I forgot to say that <code>tf.slice(string, [0], [4])</code> also doesn't work with same error.</p>