NumPy is a Python library for efficient numerical computation. It provides mathematical operations suited to translating quantitative ideas into reusable analytical solutions. section 1.2.1 section 1.4.3
NumPy supports quantitative workflows by:
- Performing arithmetic computations programmatically rather than manually. section 1.4.3
- Applying matrix multiplication to calculate successive or multi-period state distributions. section 11.2.2
- Automating calculations to improve efficiency and precision when working with complex systems and large data sets. section 11.2.2
Forecasting market shares with matrix operations
Represent initial market shares as pi_0 and transitions as matrix P. Compute period 1 with np.dot(pi_0, P), then compute period 2 either from period 1 or directly with P2 = np.dot(P, P) followed by np.dot(pi_0, P2). Both methods produce [0.39012, 0.31454, 0.22803, 0.06731] for period 2. section 11.2.2
>>> import numpy as np >>> pi_0 = np.array([0.40, 0.35, 0.20, 0.05]) >>> P = np.array([ >>> [0.85, 0.06, 0.07, 0.02], >>> [0.08, 0.80, 0.10, 0.02], >>> [0.10, 0.10, 0.75, 0.05], >>> [0.12, 0.10, 0.08, 0.70] >>> ])
Inspect the NumPy definitions for the initial probability vector and transition matrix used in the market-share forecast. section 11.2.2






