kopia lustrzana https://github.com/animator/learn-python
Update installation_features.md
rodzic
bcf4df6d7d
commit
e6a7ceee0c
|
@ -1,13 +1,25 @@
|
|||
## Installation of Scipy
|
||||
### Install using the command:
|
||||
#### C:\Users\Your Name>pip install scipy
|
||||
You can also use a Python distribution that already has Scipy installed like Anaconda, or Spyder.
|
||||
|
||||
You can install scipy using the command:
|
||||
|
||||
```
|
||||
$ pip install scipy
|
||||
```
|
||||
|
||||
You can also use a Python distribution that already has Scipy installed like Anaconda, or Spyder.
|
||||
|
||||
### Importing SciPy
|
||||
#### from scipy import constants
|
||||
|
||||
```python
|
||||
from scipy import constants
|
||||
```
|
||||
|
||||
## Key Features of SciPy
|
||||
### 1. Numerical Integration
|
||||
#### It helps in computing definite or indefinite integrals of functions
|
||||
```
|
||||
|
||||
It helps in computing definite or indefinite integrals of functions
|
||||
|
||||
```python
|
||||
from scipy import integrate
|
||||
|
||||
#Define the function to integrate
|
||||
|
@ -18,13 +30,18 @@ def f(x):
|
|||
result, error = integrate.quad(f, 0, 1)
|
||||
print(result)
|
||||
```
|
||||
|
||||
#### Output
|
||||
|
||||
```
|
||||
0.33333333333333337
|
||||
```
|
||||
|
||||
### 2. Optimization
|
||||
#### It can be used to minimize or maximize functions, here is an example of minimizing roots of an equation
|
||||
```
|
||||
|
||||
It can be used to minimize or maximize functions, here is an example of minimizing roots of an equation
|
||||
|
||||
```python
|
||||
from scipy.optimize import minimize
|
||||
|
||||
# Define an objective function to minimize
|
||||
|
@ -35,13 +52,18 @@ def objective(x):
|
|||
result = minimize(objective, x0=0)
|
||||
print(result.x)
|
||||
```
|
||||
|
||||
#### Output
|
||||
|
||||
```
|
||||
array([-1.30644012])
|
||||
```
|
||||
|
||||
### 3. Linear Algebra
|
||||
#### Solving Linear computations
|
||||
```
|
||||
|
||||
Solving Linear computations
|
||||
|
||||
```python
|
||||
from scipy import linalg
|
||||
import numpy as np
|
||||
|
||||
|
@ -55,13 +77,18 @@ b = np.array([5, 6])
|
|||
x = linalg.solve(A, b)
|
||||
print(x)
|
||||
```
|
||||
|
||||
#### Output
|
||||
|
||||
```
|
||||
array([-4. , 4.5])
|
||||
```
|
||||
|
||||
### 4. Statistics
|
||||
#### Performing statistics functions, like here we'll be distributing the data
|
||||
```
|
||||
|
||||
Performing statistics functions, like here we'll be distributing the data
|
||||
|
||||
```python
|
||||
from scipy import stats
|
||||
import numpy as np
|
||||
|
||||
|
@ -71,9 +98,12 @@ data = stats.norm.rvs(loc=0, scale=1, size=1000)
|
|||
# Fit a normal distribution to the data
|
||||
mean, std = stats.norm.fit(data)
|
||||
```
|
||||
|
||||
### 5. Signal Processing
|
||||
#### To process spectral signals, like EEG or MEG
|
||||
```
|
||||
|
||||
To process spectral signals, like EEG or MEG
|
||||
|
||||
```python
|
||||
from scipy import signal
|
||||
import numpy as np
|
||||
|
||||
|
@ -85,14 +115,21 @@ signal = np.sin(2 * np.pi * 5 * t) + 0.5 * np.random.randn(1000)
|
|||
b, a = signal.butter(4, 0.1, 'low')
|
||||
filtered_signal = signal.filtfilt(b, a, signal)
|
||||
```
|
||||
|
||||
The various filters applied that are applied here, are a part of signal analysis at a deeper level.
|
||||
|
||||
### 6. Sparse Matrix
|
||||
#### The word ' sparse 'means less, i.e., the data is mostly unused during some operation or analysis. So, to handle this data, a Sparse Matrix is created
|
||||
#### There are two types of Sparse Matrices:
|
||||
##### 1. CSC: Compressed Sparse Column, it is used for efficient math functions and for column slicing
|
||||
##### 2. CSR: Compressed Sparse Row, it is used for fast row slicing
|
||||
|
||||
The word ' sparse 'means less, i.e., the data is mostly unused during some operation or analysis. So, to handle this data, a Sparse Matrix is created
|
||||
|
||||
There are two types of Sparse Matrices:
|
||||
|
||||
1. CSC: Compressed Sparse Column, it is used for efficient math functions and for column slicing
|
||||
2. CSR: Compressed Sparse Row, it is used for fast row slicing
|
||||
|
||||
#### In CSC format
|
||||
```
|
||||
|
||||
```python
|
||||
from scipy import sparse
|
||||
import numpy as np
|
||||
|
||||
|
@ -104,17 +141,22 @@ values = np.array([1, 2, 1])
|
|||
|
||||
sparse_matrix_csc = sparse.csc_matrix((values, (row_indices, col_indices)))
|
||||
```
|
||||
|
||||
#### In CSR format
|
||||
```
|
||||
|
||||
```python
|
||||
from scipy import sparse
|
||||
import numpy as np
|
||||
|
||||
data = np.array([[0, 0], [0, 1], [2, 0]])
|
||||
sparse_matrix = sparse.csr_matrix(data)
|
||||
```
|
||||
|
||||
### 7. Image Processing
|
||||
#### It is used to process the images, like changing dimensions or properties. For example, when you're doing a project on medical imaging, this library is mainly used.
|
||||
```
|
||||
|
||||
It is used to process the images, like changing dimensions or properties. For example, when you're doing a project on medical imaging, this library is mainly used.
|
||||
|
||||
```python
|
||||
from scipy import ndimage
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
@ -127,4 +169,5 @@ blurred_image = ndimage.gaussian_filter(image, sigma=1)
|
|||
plt.imshow(blurred_image)
|
||||
plt.show()
|
||||
```
|
||||
#### The gaussian blur is one of the properties of the ' ndimage ' package in SciPy libraries, it used for better understanding of the image.
|
||||
|
||||
The gaussian blur is one of the properties of the ' ndimage ' package in SciPy libraries, it used for better understanding of the image.
|
||||
|
|
Ładowanie…
Reference in New Issue