Hi
exactly I wrote what you mentioned( for gradient in gradients:
np.clip(gradient, -maxValue, maxValue, out = gradient)), but this error appeared.
what’s wrong?
error:
Gradients for mValue=10
TypeError Traceback (most recent call last)
in
29 print("\033[92mAll tests passed!\x1b[0m")
30
—> 31 clip_test(clip, 10)
32 clip_test(clip, 5)
33
in clip_test(target, mValue)
10 gradients = {“dWax”: dWax, “dWaa”: dWaa, “dWya”: dWya, “db”: db, “dby”: dby}
11
—> 12 gradients2 = target(gradients, mValue)
13 print(“gradients[“dWaa”][1][2] =”, gradients2[“dWaa”][1][2])
14 print(“gradients[“dWax”][3][1] =”, gradients2[“dWax”][3][1])
in clip(gradients, maxValue)
20 # Clip to mitigate exploding gradients, loop over [dWax, dWaa, dWya, db, dby]. (≈2 lines)
21 for gradient in gradients:
—> 22 np.clip(gradient, -maxValue, maxValue, out = gradient)
23 ### END CODE HERE ###
24
<array_function internals> in clip(*args, **kwargs)
/opt/conda/lib/python3.7/site-packages/numpy/core/fromnumeric.py in clip(a, a_min, a_max, out, **kwargs)
2082
2083 “”"
→ 2084 return _wrapfunc(a, ‘clip’, a_min, a_max, out=out, **kwargs)
2085
2086
/opt/conda/lib/python3.7/site-packages/numpy/core/fromnumeric.py in _wrapfunc(obj, method, *args, **kwds)
56 bound = getattr(obj, method, None)
57 if bound is None:
—> 58 return _wrapit(obj, method, *args, **kwds)
59
60 try:
/opt/conda/lib/python3.7/site-packages/numpy/core/fromnumeric.py in _wrapit(obj, method, *args, **kwds)
45 except AttributeError:
46 wrap = None
—> 47 result = getattr(asarray(obj), method)(*args, **kwds)
48 if wrap:
49 if not isinstance(result, mu.ndarray):
/opt/conda/lib/python3.7/site-packages/numpy/core/_methods.py in _clip(a, min, max, out, casting, **kwargs)
130 else:
131 return _clip_dep_invoke_with_casting(
→ 132 um.clip, a, min, max, out=out, casting=casting, **kwargs)
133
134 def _mean(a, axis=None, dtype=None, out=None, keepdims=False):
/opt/conda/lib/python3.7/site-packages/numpy/core/_methods.py in _clip_dep_invoke_with_casting(ufunc, out, casting, *args, **kwargs)
83 # try to deal with broken casting rules
84 try:
—> 85 return ufunc(*args, out=out, **kwargs)
86 except _exceptions._UFuncOutputCastingError as e:
87 # Numpy 1.17.0, 2019-02-24
TypeError: return arrays must be of ArrayType