votes up 1

Argument num_rows must be a 0-D Tensor. Found: %s

Package:
Exception Class:
ValueError

Raise code

              " %s" % self._num_columns)

    num_rows_static = self._num_rows_static
    num_columns_static = self._num_columns_static

    if num_rows_static is not None:
      if num_rows_static.ndim != 0:
        raise ValueError("Argument num_rows must be a 0-D Tensor.  Found:"
                         " %s" % num_rows_static)

      if num_rows_static < 0:
        raise ValueError("Argument num_rows must be non-negative.  Found:"
                         " %s" % num_rows_static)
    if num_columns_static is not None:
      if num_columns_static.ndim != 0:
        
😲 Agile task management is now easier than calling a taxi. #Tracklify

Ways to fix

votes up 2 votes down

num_rows must be a scalar, not a tensor or a list.

Reproducing the error:

 from tensorflow.linalg import LinearOperatorZeros
 operator = LinearOperatorZeros(num_rows=[2], batch_shape=[2])
 operator.to_dense()


The error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-14-beb02f2e967b> in <module>()
      1 from tensorflow.linalg import LinearOperatorZeros
----> 2 operator = LinearOperatorZeros(num_rows=[2], batch_shape=[2])
      3 operator.to_dense()

/usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/linalg/linear_operator_zeros.py in __init__(self, num_rows, num_columns, batch_shape, dtype, is_non_singular, is_self_adjoint, is_positive_definite, is_square, assert_proper_shapes, name)
    226       self._num_columns_static = tensor_util.constant_value(self._num_columns)
    227 
--> 228       self._check_domain_range_possibly_add_asserts()
    229 
    230       if (self._num_rows_static is not None and

/usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/linalg/linear_operator_zeros.py in _check_domain_range_possibly_add_asserts(self)
    400       if num_rows_static.ndim != 0:
    401         raise ValueError("Argument num_rows must be a 0-D Tensor.  Found:"
--> 402                          " %s" % num_rows_static)
    403 
    404       if num_rows_static < 0:

ValueError: Argument num_rows must be a 0-D Tensor.  Found: [2]


Fixed:

 from tensorflow.linalg import LinearOperatorZeros
 operator = LinearOperatorZeros(num_rows=2, batch_shape=[2])
 operator.to_dense()


Output:

<tf.Tensor: shape=(2, 2, 2), dtype=float32, numpy=
array([[[0., 0.],
        [0., 0.]],

       [[0., 0.],
        [0., 0.]]], dtype=float32)>

Jul 09, 2021 kellemnegasi answer
kellemnegasi 31.6k

Add a possible fix

Please authorize to post fix