Introduction
SciPy helps solve math and science problems easily. It connects with other tools to do more things together.
Jump into concepts and practice - no test required
SciPy helps solve math and science problems easily. It connects with other tools to do more things together.
# SciPy works well with NumPy, Matplotlib, and Pandas import numpy as np import scipy import matplotlib.pyplot as plt import pandas as pd
SciPy builds on NumPy arrays for fast math.
It works well with Matplotlib for plotting and Pandas for data tables.
import numpy as np from scipy import integrate import matplotlib.pyplot as plt x = np.linspace(0, 10, 100) y = np.sin(x) area = integrate.simps(y, x) plt.plot(x, y) plt.title(f"Area under curve: {area:.2f}") plt.show()
import pandas as pd from scipy import stats data = pd.Series([1, 2, 2, 3, 4, 5, 5, 6]) mode = stats.mode(data) print(f"Most common value: {mode.mode[0]}")
This program uses SciPy to find the lowest point of a curve, NumPy to create data points, and Matplotlib to show the curve and minimum visually.
import numpy as np from scipy import optimize import matplotlib.pyplot as plt # Define a simple function def f(x): return x**2 + 4*x + 4 # Find minimum using SciPy optimize min_result = optimize.minimize(f, x0=0) # Create data for plot x = np.linspace(-10, 2, 100) y = f(x) # Plot function and minimum point plt.plot(x, y, label='f(x)') plt.scatter(min_result.x, min_result.fun, color='red', label='Minimum') plt.legend() plt.title('Function and its minimum') plt.xlabel('x') plt.ylabel('f(x)') plt.show() print(f"Minimum value of f(x) is {min_result.fun:.2f} at x = {min_result.x[0]:.2f}")
SciPy is not alone; it works best with other Python tools.
Using SciPy with NumPy, Matplotlib, and Pandas makes data science easier.
SciPy connects with many tools to solve bigger problems.
It uses NumPy for numbers, Matplotlib for pictures, and Pandas for tables.
Working together, these tools help you do more with less effort.
import numpy as np
import scipy.integrate as integrate
result, error = integrate.quad(np.sin, 0, np.pi)
print("{:.2f}".format(round(result, 2)))import scipy.linalg matrix = [[1, 2], [3, 4]] inv = scipy.linalg.inv(matrix) print inv