简体   繁体   中英

How do you center N*M matrix in Python using sklearn

I have a N by M array where N corresponds to the number of points in an M dimensional space. I would like to center these points by subtracting the mean point using the learn library.

you don't need sklearn for this, you'll use numpy (which is also used by scikit-learn). Here is an example for N = 2 and M = 3:

import numpy as np
points = np.array([
   [1.,2.,3.],   # 1st point
   [4.,5.,6.]]   # 2nd point
)

meanPoint = points.mean(axis = 0)

# subtract mean point
points -= meanPoint

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM