python--mat(),array(),fig.add_subplot(xyz)函数

python语言abs() 函数返回数字的绝对值。

import numpy as np
np.shape(数组)[0]

import numpy as np
a=np.array([[1,2,3],[2,4,5]])
a
<<<<array([[1, 2, 3],
       [2, 4, 5]])
np.shape(a)
<<<(2, 3)
np.shape(a)[0]   #需要显示行
<<<   2
np.shape(a)[1]    #需要显示列
<<<   3

fig.add_subplot(xyz)

x表示行,y表示列,z表示位置

fig = plt.figure(figsize = (5,5)) 表明画图空间5x5
ax = fig.add_subplot(223)则表示把5x5的图片切分2行2列的小方格(共有4小格),在第三个格里画图。

import matplotlib.pyplot as plt
fig = plt.figure(figsize = (5,5)) 
#ax = fig.add_subplot(222)
#ax = fig.add_subplot(222)
#ax = fig.add_subplot(223)
ax = fig.add_subplot(332)
xcord1=[1,4,6,8]
ycord1=[2.3,4,5,6]
ax.scatter(xcord1, ycord1, s = 20, c = 'red', marker = 's',alpha=.5)
plt.show()

tup

np.mat()用法

m= np.mat([1,2,3])
m
<<<matrix([[1, 2, 3]])
m[0,1]              #第一行,第2个数据
<<<<  2
m[0][1]             #注意不能像数组那样取值了
<<<IndexError: index 1 is out of bounds for axis 0 with size 1
m= np.mat([[1,2,3],[3,5,6]])
m[1][1]             #注意不能像数组那样取值了
>>>IndexError: index 1 is out of bounds for axis 0 with size 1
m= np.mat([[1,2,3],[3,5,6]])
m[1,1]     
>>>  5       

np.array()

n=np.array([1,2,3])
n[1]
<<< 2
n[0,1]   #一维数组情况下不可以
>>>>IndexError: too many indices for array
n=np.array([[1,2,3],[3,5,6]])
>>>array([[1, 2, 3],
       [3, 5, 6]])
n[1][1]
>>>   5
n[0,1]     #二维数组可以
>>>  2

transpose()

m= np.mat([[1,2,3],[3,5,6]])
print(m) 
print("-------------------"*2,'\n')
print(m.transpose()) 
>>>
[[1 2 3]
 [3 5 6]]
-------------------------------------- 

[[1 3]
 [2 5]
 [3 6]]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值