python创建数组

# -*- coding: utf-8 -*-
"""
Created on Wed Apr 24 17:17:36 2019

@author: juan
"""
#python 创建数组
#1、第一种方式不可取,会将每一个子数组的第一项都置为1,原因是每一个子数组都是第一个子数组的引用。
#因此第一个子数组改变。其余也随之改变
t=[[0]*2]*3
t[0][0]=1
print(t)

#2、通过循环
t1=[[0]*2 for _ in range(3)]
t1[0][0]=1
print(t1)

t2=[[0 for i in range(2)] for j in range(3)]
t2[0][0]=8
print(t2)

t3=[[[0]*3 for _ in range(4)] for _ in range(2)]
t3[0][0][0]=6
print(t3)

#3、通过numpy来构建
import numpy as np
t4=np.zeros((3,5))
t4[0][0]=9
print(t3)

t5=np.arange(6).reshape(2,3)
print(t5)

#创建dict的三种方式
dict1={'a':1,'b':2}

dict2={}
dict2['a']=1
dict2['b']=2

dict3=dict(a=1,b=2)
print(dict1,dict2,dict3)



#1、cal_power
import math
a=10*math.log10(8.29545e-13/1E-3)
print(a)

#2、获取随机种子
import random
b=random.randint(0,30)
print(b)

#3、画折线图
import matplotlib.pyplot as plt
import numpy as np
x=range(1,4)
y=[4,5,6]
plt.figure(figsize=(10,5))
plt.plot(x,y,label='HeMcs11')
plt.scatter([1,2,3],[4,5,6],s=30,marker='*')
plt.legend()
plt.title("gain")
plt.ylabel("output")
plt.xlabel("ampdu size")
plt.grid()
plt.xticks(np.arange(0,10,2),fontsize=1)
plt.yticks(np.arange(0,10,2))
plt.show()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值