python深度学习基于pytorch代码1.1生成Numpy数组

import numpy as np
lst1 = [3.14, 2.17, 0, 1, 2]
nd1 = np.array(lst1)
print(nd1)
print(type(nd1))
lst2 = [[3.14, 2.17, 0, 1, 2], [1, 2, 3, 4, 5]]
nd2 = np.array(lst2)
print(nd2)
print(type(nd2))
nd3 = np.random.random([3, 3])
print(nd3)
print("nd3的形状为:", nd3.shape)
np.random.seed(123)
nd4 = np.random.randn(2, 3)
print(nd4)
np.random.shuffle(nd4)
print("随机打乱后数据:")
print(nd4)
print(type(nd4))
nd5 = np.zeros([3, 3])
#np.zeros_like(nd5)
#生成全是0的3*3矩阵
nd6 = np.ones([3, 3])
nd7 = np.eye(3)
nd8 =np.diag([1, 2, 3])
print(nd5)
print(nd6)
print(nd7)
print(nd8)
nd9 = np.random.random([5, 5])
np.savetxt(X=nd9, fname='./test1.txt')
nd10 = np.loadtxt('./test1.txt')
print(nd10)
print(np.arange(10))
print(np.arange(0,10))
print(np.arange(1, 4, 0.5))
print(np.arange(9, -1, -1))
print(np.linspace(0, 1, 10))
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值