Python使用np.c_和np.r_实现数组转换成矩阵

时间:2022-05-11 23:51:49

# -*- coding: utf-8 -*-
"""
Created on Sat Jun 30 14:49:22 2018

@author: zhen
"""

import numpy as np
a = np.array([[1,2,3],[11,22,33]])
b = np.array([[4,5,6],[44,55,66]])
# 数组连接成矩阵
c = np.c_[a,b]
r = np.r_[a,b]
print('-------------按行转换成矩阵-----------------')
print(c)
print('-------------按列转换成矩阵-----------------')
print(r)

结果:

Python使用np.c_和np.r_实现数组转换成矩阵