1. Np.size and Np.prod
1 Import NumPy as NP 2 x = Np.zeros ((3, 5, 2), dtype=np.complex128)3# Ndarray.size is the number of elements in the array4# equivalent to Np.prod (a.shape)5Print (x.size)6print(Np.prod (X.shape))
2. The enumerate () function is a python built-in function, enumerated on a dictionary, enumerated, and, for an iterative (iterable)/Ergodic object, enumerate an index sequence that can be used to obtain both the index and the value. Note: Enumerate is used in the for loop to get counted.
Examples of Use:
(1) For lists, you must traverse the index and iterate over the elements
1List1 = ["it","is a","a","Test"]2 #Method 13 forIinchRange (len (list1)):4 Print(i, list1[i])5 #Method 2 Use Enumerate6 forIndex, iteminchEnumerate (list1):7 Print(Index, item)
(2) Enumerate can also receive the second parameter, which is used to specify the starting value of an index
1List1 = ["it","is a","a","Test"]2 forIndex, iteminchEnumerate (List1, 1):3 Print(Index, item)4 " "5 1 This6 2 is7 31 x8 4 Testing9 " "
(3) Enumerate used to count file lines
1 # Method 1 2 ' R ' ). ReadLines ())3# Method 24 count =-15 for inch ' R ' )):6 count + = 1
Python Learning Note 1-numpy/enumerate