当前位置: 首页 > news >正文

2022世界物联网百度网站怎样优化排名

2022世界物联网,百度网站怎样优化排名,网站谁做的,网站建设结算方式系列文章目录 Numpy学习——创建数组及常规操作(数组创建、切片、维度变换、索引、筛选、判断、广播) Tensor学习——创建张量及常规操作(创建、切片、索引、转换、维度变换、拼接) 基础学习——numpy与tensor张量的转换 基础学习…

系列文章目录

Numpy学习——创建数组及常规操作(数组创建、切片、维度变换、索引、筛选、判断、广播)
Tensor学习——创建张量及常规操作(创建、切片、索引、转换、维度变换、拼接)
基础学习——numpy与tensor张量的转换
基础学习——关于list、numpy、torch在float和int等数据类型转换方面的总结


文章目录

  • 系列文章目录
  • 前言
    • 1、数据类型介绍
    • 2、numpy与torch的一些数组函数的区别
      • 1、empty()
      • 2、randint()
      • 3、normal()
      • 4、transpose()
    • 3、int和float的转换
      • 1、一个数的转换
      • 2、list类型转换
      • 3、numpy类型转换
      • 4、torch数据类型转换


前言

因为自己最近总是遇到一些list、numpy、torch的数据类型转换错误,特别是不同类型间的float转int或int转float,总是遇到错误,所以在这里总结一下。


1、数据类型介绍

Python中基本数据类型主要可分为以下几种:
1.数字(Number);
2.字符串(String);
3.列表(List);
4.字典(Dictionary);
5.元组(Tuple);

在Python3中,支持的数字类型有:
1.int–整型
2.float–浮点型
3.bool–布尔型
4.fractions–分数
5.complex–复数

2、numpy与torch的一些数组函数的区别

导入包

import torch
import torch.nn as nn
import numpy as np 
import math

1、empty()

空数组:返回给定形状和类型的新数组,而不初始化条目

a = np.empty([3,3]) 
b = torch.empty([3,3])
print(a)
print(b)

结果:

[[6.23042070e-307 4.67296746e-307 1.69121096e-306][3.22647253e-307 2.67018777e-306 1.42413555e-306][1.78019082e-306 1.37959740e-306 2.29178686e-312]]
tensor([[0., 0., 0.],[0., 0., 0.],[0., 0., 0.]])

2、randint()

随机生成整数

a= np.random.randint(40, 100, (3, 4))
b = torch.randint(40, 100, (3, 4))
print(a)
print(b)

结果:

[[46 47 55 88][73 96 44 98][96 41 64 45]]
tensor([[98, 65, 57, 97],[90, 74, 45, 64],[67, 54, 79, 45]])

3、normal()

创建符合正态分布的4行5列数据

a = np.random.normal(0, 1, (4, 5))
b = torch.normal(0, 1, size = (4, 5))   
print(a)
print(b)

结果;

[[-0.97259852  1.51207726  0.54528577  1.1024245   0.47090239][ 0.03231742  0.51741803  0.25911092 -1.14377841 -0.02595822][-0.42955202 -0.25546385  0.74112698 -1.57833126  0.69611583][ 0.08953791  0.32776525  0.74939352 -0.43138969  0.26458097]]
tensor([[ 0.6898,  0.4377,  1.8008, -1.3965, -1.7741],[-0.0722,  0.6072,  0.1556,  0.2961, -0.6501],[-1.6929, -1.0789,  2.0120,  1.0724,  1.6193],[ 1.1412, -0.9807,  0.5462, -0.3795, -1.2053]])

4、transpose()

维度转换函数np和torch的区别

import torch
import numpy as np 
a= np.random.randint(40, 100, (3, 4,5))
b = np.transpose(a,(2,1,0))
print(a.shape)
print(b.shape)# torch.transpose只能由两个维度交换
c = torch.randn(2,3,4)
d = torch.transpose(c,0,1)
print(c.shape)
print(d.shape)

结果:

(3, 4, 5)
(5, 4, 3)
torch.Size([2, 3, 4])
torch.Size([3, 2, 4])

3、int和float的转换

导入包

import torch
import torch.nn as nn
import numpy as np 
import math

1、一个数的转换

a = float(1.0)
b = int(a)
print(a)
print(b)

结果:

1.0
1

2、list类型转换

列表类型转换

a = [0.0567, 9.2345, 8.1986, 4.3333]
c = [1,2,3,4]b = [int(a) for a in a] # 或者用下面这个
# b = list(map(int, a))
# b = [math.ceil(a) for a in a]print(a)
print(b)
d = list(map(float, c))
print(c)
print(d)

结果:

[0.0567, 9.2345, 8.1986, 4.3333]
[0, 9, 8, 4]
[1, 2, 3, 4]
[1.0, 2.0, 3.0, 4.0]

3、numpy类型转换

numpy float 转 int
其他类型转换也是一样的

a = np.array([1, 2], dtype = 'float32')        # dtype参数
print(a.dtype,a)
b = a.astype(np.int8)  
print(b.dtype,b)

结果:

float32 [1. 2.]
int8 [1 2]

astype里的类型还可以填这些:
在这里插入图片描述

4、torch数据类型转换

在Tensor后加.long(), .int(), .float(), .double()

a = torch.tensor([1, 2], dtype =torch.int8)        # dtype参数
print(a.dtype,a)
b = a.float()
print(b.dtype,b)

结果:

torch.int8 tensor([1, 2], dtype=torch.int8)
torch.float32 tensor([1., 2.])

用.to()函数进行转换

a = torch.tensor([1, 2], dtype =torch.uint8)        # dtype参数
print(a.dtype,a)
b = a.to(dtype =torch.float32)
print(b.dtype,b)

结果:

torch.uint8 tensor([1, 2], dtype=torch.uint8)
torch.float32 tensor([1., 2.])

其他类型转换也是一样的。
下面是一些类型的名称。
在这里插入图片描述

http://www.yidumall.com/news/14373.html

相关文章:

  • 专做机票网站的软件公司谷歌搜索引擎免费入口
  • 湖南省人民政府办公厅seo网络营销是什么意思
  • 网站关键词优化方法郑州seo技术服务
  • 做电影电视剧网站推广c++线上培训机构哪个好
  • 全国生猪价格今日猪价行情表查询seo首页优化
  • 做英文行程的网站今日特大新闻新事
  • 网站是怎么做优化做网络推广要学些什么
  • 亚马逊 怎么做国外网站网站发布平台
  • 计算机上网题的模拟网站怎么做搜索引擎有哪些?
  • 昆明网站排名优化公司营销知识和技巧
  • 泉州营销型网站设计电商网站建设制作
  • 用国外服务器做网站百度关键词推广一年多少钱
  • 做图片的网站seo排名优化软件有用吗
  • 快看点自媒体平台注册账号入口seo搜索引擎优化哪家好
  • 租网站服务器一个月多少钱郑州专业seo哪家好
  • 注册网站会员需填写优化网站seo公司
  • 301转向 所有网站一起操作网络平台推广运营公司
  • 保定网络公司建设网站软文是什么意思
  • 物流运输做网站的素材seo百度关键词排名
  • 做网站公司 陕西渭南网络营销策划的基本原则是什么
  • 游戏建设网站seo服务套餐
  • 自学网站搭建外链吧
  • 临沂网站开发技术员怎么用网络推广
  • 网站报价表对比表怎么做数字营销服务商seo
  • 下载网站的服务器文件黄页引流推广网站
  • 深圳广告标识厂家安阳seo
  • 做网站植入广告赚钱合肥网络关键词排名
  • 一起做网店官方网站西安搜索引擎优化
  • 成都有哪些比较做网站比较好的网站seo优化是什么
  • 母婴类网站 网站建设方案书 备案余姚seo智能优化