On 25 Aug, 17:37, Matjaz Bezovnik <mbezov...@freenet.si> wrote: > Scott, thank you very much for the snippet. > > It is exactly what I looked for; simple to read and obvious as to what > it does even a month later to a non-pythonist!
Since you were talking about matrices, observe that numpy has a matrix subclass of ndarray, which e.g. changes the meaning of the * operator mean indicate matrix multiplication. Thus, >>> import numpy as np >>> np.eye(4) array([[ 1., 0., 0., 0.], [ 0., 1., 0., 0.], [ 0., 0., 1., 0.], [ 0., 0., 0., 1.]]) >>> np.matrix(np.eye(4)) matrix([[ 1., 0., 0., 0.], [ 0., 1., 0., 0.], [ 0., 0., 1., 0.], [ 0., 0., 0., 1.]]) >>> a = np.ones((4,4)) >>> a*a array([[ 1., 1., 1., 1.], [ 1., 1., 1., 1.], [ 1., 1., 1., 1.], [ 1., 1., 1., 1.]]) >>> b = np.matrix(a) >>> b*b matrix([[ 4., 4., 4., 4.], [ 4., 4., 4., 4.], [ 4., 4., 4., 4.], [ 4., 4., 4., 4.]]) >>> b**2 matrix([[ 4., 4., 4., 4.], [ 4., 4., 4., 4.], [ 4., 4., 4., 4.], [ 4., 4., 4., 4.]]) >>> b**4 matrix([[ 64., 64., 64., 64.], [ 64., 64., 64., 64.], [ 64., 64., 64., 64.], [ 64., 64., 64., 64.]]) In Matlab, you use .* vs. * and .^ vs. ^ to obtain the same effect. In NumPy we use different classes for arrays and matrices. Sturla Molden -- http://mail.python.org/mailman/listinfo/python-list