[PYTHON] Normarize data with Scipy

I often forget it, so I quote it from scipy.org and make a note.

>>> import numpy as np
>>> from scipy import stats

>>> a = np.array([ 0.7972,  0.0767,  0.4383,  0.7866,  0.8091,  0.1954,
                   0.6307, 0.6599,  0.1065,  0.0508])

>>> stats.zscore(a)
array([ 1.1273, -1.247 , -0.0552,  1.0923,  1.1664, -0.8559,  0.5786,
        0.6748, -1.1488, -1.3324])

>>> b = np.array([[ 0.3148,  0.0478,  0.6243,  0.4608],
                  [ 0.7149,  0.0775,  0.6072,  0.9656],
                  [ 0.6341,  0.1403,  0.9759,  0.4064],
                  [ 0.5918,  0.6948,  0.904 ,  0.3721],
                  [ 0.0921,  0.2481,  0.1188,  0.1366]])

>>> z_score = stats.zscore(b, axis=1, ddof=1)

>>> z_score
array([[-0.19264823, -1.28415119,  1.07259584,  0.40420358],
       [ 0.33048416, -1.37380874,  0.04251374,  1.00081084],
       [ 0.26796377, -1.12598418,  1.23283094, -0.37481053],
       [-0.22095197,  0.24468594,  1.19042819, -1.21416216],
       [-0.82780366,  1.4457416 , -0.43867764, -0.1792603 ]])

>>> np.allclose(np.mean(z_score, axis=1), np.zeros(5))

Reference (quote) scipy.org

Recommended Posts

Normarize data with Scipy
LPC with Scipy
ICA with Scipy
CORDIC with Scipy
Data analysis with python 2
Visualize data with Streamlit
Data visualization with pandas
Create filter with scipy
Data manipulation with Pandas!
Shuffle data with pandas
Data Augmentation with openCV
Data analysis with Python
LOAD DATA with PyMysql
Sample data created with python
Graph Excel data with matplotlib (1)
Artificial data generation with numpy
Extract Twitter data with CSV
Get Youtube data with python
Clustering ID-POS data with LDA
Learn new data with PaintsChainer
Graph Excel data with matplotlib (2)
Save tweet data with Django
Use OpenBLAS with numpy, scipy
Extract peak values with scipy
Data processing tips with Pandas
Interpolate 2D data with scipy.interpolate.griddata
Read json data with python
Save & load data with joblib, pickle
Harmonic mean with Python Harmonic mean (using SciPy)
Calculate sample distribution with Scipy (discrete distribution)
Generate a normal distribution with SciPy
How to deal with imbalanced data
How to deal with imbalanced data
Versatile data plotting with pandas + matplotlib
Python data structures learned with chemoinformatics
Install the data files with setup.py
Parse pcap data with tshark command
Create noise-filled audio data with SoX
How to Data Augmentation with PyTorch
Process Pubmed .xml data with python
Data analysis starting with python (data visualization 1)
Manage your data with AWS RDS
Try data parallelism with Distributed TensorFlow
[Python scipy] Upscale / downscale 2D data
Data science environment construction with Docker
Data analysis starting with python (data visualization 2)
Merge JSON format data with Ansible
Implement "Data Visualization Design # 2" with matplotlib
Python application: Data cleansing # 2: Data cleansing with DataFrame
Subtitle data created with Amazon Transcribe
Forecasting time series data with Simplex Projection
Data accumulation with GCP's permanent free frame
Get additional data in LDAP with python
Receive textual data from mysql with python
[Note] Get data from PostgreSQL with Python
Predict time series data with neural network
Learn data distributed with TensorFlow Y = 2X
Process Pubmed .xml data with python [Part 2]
Add a Python data source with Redash
Retrieving food data with Amazon API (Python)
Check raw data with Kaggle's Titanic (kaggle ⑥)