Introduction to Python - Data Science, Quantitative Finance (2.0) by Li Lilan

Introduction to Python - Data Science, Quantitative Finance (2.0) by Li Lilan

Author:Li, Lilan [Li, Lilan]
Language: eng
Format: epub
Published: 2021-09-27T00:00:00+00:00


Now we have a 2D ndarray and we try to do some operations on each column and row:

>>> b.sum(axis=0) # sum of each column

array([12, 15, 18, 21])

>>>

>>> b.min(axis=1) # min of each row

array([0, 4, 8])

>>>

>>> b.cumsum(axis=1) # cumulative sum along each row

array([[ 0, 1, 3, 6],

[ 4, 9, 15, 22],

[ 8, 17, 27, 38]])

>>> b.prod(axis = 0) # matrix product for each column

array([ 0, 45, 120, 231])

Since the ndarray is a 2D, if we set axis = 2 , it will return error:

>>> b.prod(axis = 2)

AxisError: axis 2 is out of bounds for array of dimension 2

NumPy also provides familiar mathematical functions such as sin , cos , exp and sqrt . In NumPy, these are called 'universal functions'(ufunc).

>>> a = 2.4

>>> np.sqrt(a)

1.5491933384829668

>>> np.exp(a)

11.023176380641601



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.