Introduction to Python 515
Python
def biggish(A):
B = np.copy(A)
B[np.where(
abs
(A) == abs(A).max())] = 0
C = np.copy(B)
C[np.where(abs(B) == abs(B).max())] = 0
return C
Note that there is no need for “begin” or “end” statements, or braces, as the block of
statements that comprise the program is delineated by indentation. Save this program in a
file, say
myfile.py, and it can then be read into your running Python with any of
Python
In :
execfile
(’myfile.py’)
In : import myfile
In : from myfile import
*
Those three statements allow the following usages respectively:
Python
In : biggish(A)
In : myfile.biggish(A)
In : biggish(A)
It is impossible to give more than a brief “taste” of Python in a few pages, but it is an
extraordinarily powerf ul language, with a huge user base, constantly being extended, and
well worth the effort of learning it.