'ord' must be a supported vector norm, got %s
Package:
tensorflow
158813

Exception Class:
ValueError
Raise code
else:
if not (isinstance(axis, int) or axis is None):
raise ValueError(
"'axis' must be None, an integer, or a tuple of 2 unique integers")
supported_vector_norms = ['euclidean', 1, 2, np.inf]
if (not np.isreal(ord) or ord <= 0) and ord not in supported_vector_norms:
raise ValueError("'ord' must be a supported vector norm, got %s" % ord)
if axis is not None:
axis = (axis,)
with ops.name_scope(name, 'norm', [tensor]):
tensor = ops.convert_to_tensor(tensor)
if ord in ['fro', 'euclidean', 2, 2.0]:
🙏 Scream for help to Ukraine
Today, 25th May 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this 😠, civilians and children are dying too!
We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.
Links to the raise (1)
https://github.com/tensorflow/tensorflow/blob/7acd515ec218b414d5b16e6710268ac03d9f5421/tensorflow/python/ops/linalg_ops.py#L724Ways to fix
The parameter "ord"
in the tensorflow function tf.norm
specifies the order of the norm to be computed. The supported(valid) values are listed as follows:
'fro', 'euclidean', 1, 2, np.inf, anyother postive real number
negative values, 0 and any other outside the supported values causes this error.
It can be a simple typo error in the name of the norm. E.g. writing 'euclidan'
instead of 'euclidean'
How to reproduce the error:
- Setup and installation
pip install --user pipenv
mkdir test_folder
cd test_folder
pipenv shell
pipenv install tensorflow
import tensorflow as tf
x = tf.random.uniform(shape=[2,3])
print(tf.norm(x,ord='euclidan'))
The error:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-17-865028f5aff8> in <module>()
1 import tensorflow as tf
2 x = tf.random.uniform(shape=[2,3])
----> 3 print(tf.norm(x,ord='euclidan'))
/usr/local/lib/python3.7/dist-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs)
204 """Call target, and fall back on dispatchers if there is a TypeError."""
205 try:
--> 206 return target(*args, **kwargs)
207 except (TypeError, ValueError):
208 # Note: convert_to_eager_tensor currently raises a ValueError, not a
/usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/linalg_ops.py in norm_v2(tensor, ord, axis, keepdims, name)
626 axis=axis,
627 keepdims=keepdims,
--> 628 name=name)
629
630
/usr/local/lib/python3.7/dist-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs)
204 """Call target, and fall back on dispatchers if there is a TypeError."""
205 try:
--> 206 return target(*args, **kwargs)
207 except (TypeError, ValueError):
208 # Note: convert_to_eager_tensor currently raises a ValueError, not a
/usr/local/lib/python3.7/dist-packages/tensorflow/python/util/deprecation.py in new_func(*args, **kwargs)
533 'in a future version' if date is None else ('after %s' % date),
534 instructions)
--> 535 return func(*args, **kwargs)
536
537 doc = _add_deprecated_arg_notice_to_docstring(
/usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/linalg_ops.py in norm(tensor, ord, axis, keepdims, name, keep_dims)
722 supported_vector_norms = ['euclidean', 1, 2, np.inf]
723 if (not np.isreal(ord) or ord <= 0) and ord not in supported_vector_norms:
--> 724 raise ValueError("'ord' must be a supported vector norm, got %s" % ord)
725 if axis is not None:
726 axis = (axis,)
ValueError: 'ord' must be a supported vector norm, got euclidan
Fixed version of the code:
correct the typo in the word "euclidean".
import tensorflow as tf
x = tf.random.uniform(shape=[2,3])
print(tf.norm(x,ord='euclidean'))
Output:
tf.Tensor(0.7575242, shape=(), dtype=float32)
Add a possible fix
Please authorize to post fix