
510 A Computational Introduction to Digital Image Processing, Second Edition
Python
In : B = A-1
In : print A.dot(B)
[[ 24 30 36]
[ 51 66 81]
[ 78 102 126]]
Note that we invoked the sqrt function from numpy, which operates on arrays. The sqrt
function f rom
math
is designed only to operate on single numbers:
Python
In : math.sqrt(A)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-69-8214aa97e221> in <module>()
----> 1 math.sqrt(A)
TypeError: only length-1 arrays can be converted to Python scalars
Here is an example of two functions sqrt with the same name, but with completely ...