from tensorflow.python.ops import array_ops

            array_ops.size(tensor.shape) + dim, [1])
      else:
        expand_dims = [dim]
      expanded_shape = array_ops.concat(
          0, (array_ops.slice(tensor.shape, [0], expand_dims), [1],
              array_ops.slice(tensor.shape, expand_dims, [-1])),
          name='expanded_shape')
      expanded = sparse_ops.sparse_reshape(
