import tensorflow as tf

  shape = np.array(shape)
  tt_rank = np.array(tt_rank)
  _validate_input_parameters(is_tensor=True, shape=shape, tt_rank=tt_rank,
                             batch_size=batch_size)
  num_dims = shape.size
  if tt_rank.size == 1:
    tt_rank = tt_rank * np.ones(num_dims - 1)
    tt_rank = np.insert(tt_rank, 0, 1)
    tt_rank = np.append(tt_rank, 1)
  tt_rank = tt_rank.astype(int)

  cr_exponent = -1.0 / (2 * num_dims)
  var = np.prod(tt_rank ** cr_exponent)
  cr_stddev = stddev ** (1.0 / num_dims) * var
  with tf.name_scope(name):
    tt = tensor_batch_with_random_cores(shape, tt_rank=tt_rank, stddev=cr_stddev,
                                        batch_size=batch_size, dtype=dtype)

  if np.abs(mean) < 1e-8:
    return tt
  else:
    raise NotImplementedError('non-zero mean is not supported yet')


def random_matrix(shape, tt_rank=2, mean=0., stddev=1.,
                  dtype=tf.float32, name='t3f_random_matrix'):
  """Generate a random TT-matrix of the given shape with given mean and stddev.

