关于Numpy中的行向量和列向量详解

yipeiwu_com5年前Python基础

行向量

方式1

import numpy as np
b=np.array([1,2,3]).reshape((1,-1))
print(b,b.shape)

结果:

(array([[1, 2, 3]]), (1, 3))

方式2

import numpy as np
b=np.array([[1,2,3]]) #两层'[]'
print(b,b.shape)

结果

(array([[1, 2, 3]]), (1, 3))

列向量

方式1

import numpy as np
a=np.array([1,2,3]).reshape((-1,1))
print(a,a.shape)

结果:

(array([[1],
    [2],
    [3]]), (3, 1))

方式2

import numpy as np
a=np.array([[1,2,3]]).T
print(a,a.shape)

结果

(array([[1],
    [2],
    [3]]), (3, 1))

以上这篇关于Numpy中的行向量和列向量详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python executemany的使用及注意事项

使用executemany对数据进行批量插入的话,要注意一下事项: #coding:utf8 conn = MySQLdb.connect(host = “localhost”, u...

Python中实现输入超时及如何通过变量获取变量名

Python中实现输入超时及如何通过变量获取变量名

背景介绍 开发中遇到了一个需求:程序运行到某处时需要用户确认, 但不能一直傻等, 后面的程序不能被一直阻塞, 需要有个超时限制, 也就是这个程序如果在一段时间后还没有得到用户输入就执行...

Python面向对象程序设计示例小结

本文实例讲述了Python面向对象程序设计。分享给大家供大家参考,具体如下: 示例1: #encoding:utf-8 '''example 1 class test: def...

pip命令无法使用的解决方法

今天在学习Python时需要安装Requests    使用命令:pip install requests    &...

pyqt5 键盘监听按下enter 就登陆的实例

记得导入包,其他按键可类比 def keyPressEvent(self, event): if event.key() == QtCore.Qt.Key_Enter:...