Python笔记:两个二维数组利用concatenate实现拼接


import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

from sklearn.datasets import load_iris

iris = load_iris()  #加载鸢尾花数据集
iris_feature = iris.data  #特征数据
iris_target = iris.target  #分类数据
iris_f = np.ones(iris_feature.shape)
iris_t = np.ones(iris_target.shape)

iris_joint = np.concatenate((iris_feature,iris_f),axis=0) #axis=0沿着纵轴拼接,axis=1沿着横轴拼接
iris_joint2 = np.concatenate((iris_target,iris_t),axis=0)

结果
Python笔记:两个二维数组利用concatenate实现拼接_第1张图片


import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

from sklearn.datasets import load_iris

iris = load_iris()  #加载鸢尾花数据集
iris_feature = iris.data  #特征数据
iris_target = iris.target  #分类数据
iris_f = np.ones(iris_feature.shape)
iris_t = np.ones(iris_target.shape)
iris_target = iris_target.reshape(len(iris_target),1) #将一维数组转为二维数组
iris_t = iris_t.reshape(len(iris_t),1)

iris_joint = np.concatenate((iris_feature,iris_f),axis=0) #axis=0沿着纵轴拼接,axis=1沿着横轴拼接
iris_joint2 = np.concatenate((iris_target,iris_t),axis=0)

结果
Python笔记:两个二维数组利用concatenate实现拼接_第2张图片


你可能感兴趣的:(Python,python)