Created
July 31, 2018 08:43
-
-
Save danielwatson6/574d611b7cc8cf6fadb22448966d8b17 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def split_by_delimiter(ts, delimiter): | |
"""Split a numeric tensor similarly to python's `str.split` method.""" | |
ts_str = tf.reshape(tf.reduce_join(tf.as_string(ts), separator=' '), [-1]) | |
ts_slices = tf.string_split( | |
tf.string_split(ts_str, delimiter=str(delimiter)).values) | |
result = tf.SparseTensor( | |
ts_slices.indices, | |
tf.string_to_number(ts_slices.values, out_type=ts.dtype), | |
ts_slices.dense_shape) | |
return tf.sparse_tensor_to_dense(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment