【pyTorch学习笔记④】PyTorch基础·中篇

文章目录

  • 三、Numpy与Tensor
    • 3.Tensor的索引
    • 4.Tensor的广播机制
    • 5.逐元素操作
    • 6.归并操作
    • 7.比较操作
    • 8.矩阵操作
    • 9.PyTorch与Numpy的比较
  • 相关推荐

三、Numpy与Tensor

3.Tensor的索引

(1)item:若Tensor为单元素,则返回标量,否则出错

a = torch.randn(1)
print(a)
>>>tensor([-0.0288])
print(a.item())
>>>-0.028787262737751007

(2)index_select(input,dim,index):指定维度上选择一些行或列

下面介绍了两种调用方式
dim表示的是维度,二维里1和-1可以表示列,三维里2和-1可表示列
index表示的是返回的索引或序号。
如下例子中(1,1)表示的是索引第二维的第二个值,第二维表示的是列,所以是第二列。

import torch
torch.manual_seed(100)
x = torch.randn(2,3)
print(x)
>>>tensor([[ 0.3607, -0.2859, -0.3938],
        [ 0.2429, -1.3833, -2.3134]])

print(x.index_select(1,torch.LongTensor([1])))
>>>tensor([[-0.2859],
        [-1.3833]])

print(torch.index_select(x,1,torch.LongTensor([1])))
>>>tensor([[-0.2859],
        [-1.3833]])

(3)nonzero(input):获取非0元素下标

import torch
x = torch.tensor([[2,3,0],[0,3,1],[1,0,3]])
print(x)
>>>tensor([[2, 3, 0],
        [0, 3, 1],
        [1, 0, 3]])

print(x.nonzero())
>>>tensor([[0, 0],
        [0, 1],
        [1, 1],
        [1, 2],
        [2, 0],
        [2, 2]])

print(torch.nonzero(x))
>>>tensor([[0, 0],
        [0, 1],
        [1, 1],
        [1, 2],
        [2, 0],
        [2, 2]])

(4)masked_select(input,mask):使用二元值进行选择

import torch
torch.manual_seed(100)
x = torch.randn(2,3)
y = torch.randn(1,2)
print(x)
>>>tensor([[ 0.3607, -0.2859, -0.3938],
        [ 0.2429, -1.3833, -2.3134]])

# 类似Numpy的索引方式
print(x[0,:])
>>>tensor([ 0.3607, -0.2859, -0.3938])

print(x[:,-1])
>>>tensor([-0.3938, -2.3134])

# 生成是否大于0的张量
mask = x>0
# 输出mask中True对应的元素
print(torch.masked_select(x,mask))
>>>tensor([0.3607, 0.2429])

# 取出1对应的元素
mask = torch.tensor([[1,1,0],[0,0,1]],dtype=torch.bool)
print(torch.masked_select(x,mask))
>>>tensor([ 0.3607, -0.2859, -2.3134])

# 取出1,2列元素
mask = torch.tensor([1,1,0],dtype=torch.bool)
print(torch.masked_select(x,mask))
>>>tensor([ 0.3607, -0.2859,  0.2429, -1.3833])

# 取出第2行元素
mask = torch.tensor([[0],[1]],dtype=torch.bool)
print(torch.masked_select(x,mask))

>>>tensor([ 0.2429, -1.3833, -2.3134])

(5)gather(input,dim,index):在指定维度上选择数据,输出的形状与index一致

dim是维度,如二维的取值范围是[-2,1]
如下例子,0,-2表示第1维,1,-1表示第2维
x.gather(1,y)按第1维,返回y对应元素指示的x中该位置的元素。
在这里插入图片描述
在这里插入图片描述
如上两图:
当dim=1时:
当y为全0时,所以返回的每一列都是x中第0列对应的值
当y的第一个元素=1时,返回的(0,0)位置的值就是x中第1列第0行的值
在这里插入图片描述
在这里插入图片描述
如上两图:
当dim=0时:
当y为全0时,所以返回的每一行都是x中第0行对应的值
当y的第一个元素=1时,返回的(0,0)位置的值就是x中第1行第0列的值

import torch
x = torch.tensor([[2,3,0],[0,3,1],[1,0,3]])
y = torch.zeros_like(x)
print(x)
>>>tensor([[2, 3, 0],
        [0, 3, 1],
        [1, 0, 3]])

print(x.gather(1,y))
>>>tensor([[2, 2, 2],
        [0, 0, 0],
        [1, 1, 1]])

print(torch.gather(x,0,y))
>>>tensor([[2, 3, 0],
        [2, 3, 0],
        [2, 3, 0]])

print(torch.gather(x,-2,y))
>>>tensor([[2, 3, 0],
        [2, 3, 0],
        [2, 3, 0]])

y[0,0] = 1
print(x)
>>>tensor([[2, 3, 0],
        [0, 3, 1],
        [1, 0, 3]])

print(x.gather(1,y))
>>>tensor([[3, 2, 2],
        [0, 0, 0],
        [1, 1, 1]])

print(torch.gather(x,0,y))
>>>tensor([[0, 3, 0],
        [2, 3, 0],
        [2, 3, 0]])

print(torch.gather(x,-2,y))
>>>tensor([[0, 3, 0],
        [2, 3, 0],
        [2, 3, 0]])

(6)scatter_(input,dim,index,src):为gather的反操作,根据指定索引补充数据

如下例子:
index只有2行,所以只对x的前两行进行重新赋值
当dim=0时,
x[index[0][0]][0] = y[0][0] 即 x[1][0] = 1
x[index[1][1]][1] = y[1][1] 即 x[0][1] = 5
x[index[1][2]][2] = y[1][2] 即 x[0][2] = 6
x[index[1][0]][0] = y[1][0] 即 x[0][0] = 4
注:y的索引与index索引一致
在这里插入图片描述

当dim=1时,
x[0][index[0][2]] = y[0][2] 即 x[0][0] = 3
x[0][index[0][0]] = y[0][0] 即 x[0][1] = 1
x[1][index[1][2]] = y[1][2] 即 x[1][0] = 6

import torch
x = torch.tensor([[2,3,0],[0,3,1],[1,0,3]])
y = torch.tensor([[1,2,3],[4,5,6]])
index = torch.tensor([[1,0,0],[0,0,0]])
print(x)
>>>tensor([[2, 3, 0],
        [0, 3, 1],
        [1, 0, 3]])

print(y)
>>>tensor([[1, 2, 3],
        [4, 5, 6]])

print(x.scatter_(0,index,y))
>>>tensor([[4, 5, 6],
        [1, 3, 1],
        [1, 0, 3]])

print(x.scatter_(1,index,y))
>>>tensor([[3, 1, 6],
        [6, 3, 1],
        [1, 0, 3]])

4.Tensor的广播机制

import torch
import numpy as np

A = np.arange(0, 40, 10).reshape(4, 1)
B = np.arange(0, 3)
# 把ndarray转换为tensor
A1 = torch.from_numpy(A)
B1 = torch.from_numpy(B)
# tensor自动实现广播
C = A1 + B1
print(A1)
>>>tensor([[ 0],
        [10],
        [20],
        [30]], dtype=torch.int32)

print(B1)
>>>tensor([0, 1, 2], dtype=torch.int32)

print(C)
>>>tensor([[ 0,  1,  2],
        [10, 11, 12],
        [20, 21, 22],
        [30, 31, 32]], dtype=torch.int32)


# 手工配置
# 根据规则1,B1需要向A1看齐,把B变为(1,3)
B2 = B1.unsqueeze(0)
# 重复数组,分别为(4,3)矩阵
A2 = A1.expand(4,3)
B3 = B2.expand(4,3)
# 相加
C1 = A2 + B3
print(A2)
>>>tensor([[ 0,  0,  0],
        [10, 10, 10],
        [20, 20, 20],
        [30, 30, 30]], dtype=torch.int32)

print(B3)
>>>tensor([[0, 1, 2],
        [0, 1, 2],
        [0, 1, 2],
        [0, 1, 2]], dtype=torch.int32)

print(C1)
>>>tensor([[ 0,  1,  2],
        [10, 11, 12],
        [20, 21, 22],
        [30, 31, 32]], dtype=torch.int32)

5.逐元素操作

(1)绝对值abs | 加法add

import torch
t = torch.randn(1,3)
t1 = torch.randn(1,3)
print(t)
>>>tensor([[ 2.0261, -0.9644,  1.0573]])

print(t1)
>>>tensor([[ 1.0033, -0.1407,  0.4890]])

print(t.abs())
>>>tensor([[2.0261, 0.9644, 1.0573]])

print(t.add(t1))
>>>tensor([[ 3.0294, -1.1052,  1.5462]])

(2)addcdiv(t,v,t1,t2)

t + 100*(t1/t2)

import torch
t = torch.randn(1,3)
t1 = torch.randn(1,3)
t2 = torch.randn(1,3)
print(t)
>>>tensor([[-0.5238, -0.3393, -0.7081]])

print(t1)
>>>tensor([[-0.5984,  1.5229,  0.7923]])

print(t2)
>>>tensor([[ 1.5784, -1.4862, -1.5006]])

# t + 100*(t1/t2)
print(torch.addcdiv(t,100,t1,t2))
>>>tensor([[ -38.4344, -102.8099,  -53.5090]])

(3)addcmul(t,v,t1,t2)

t + 100*(t1*t2)

import torch
t = torch.randn(1,3)
t1 = torch.randn(1,3)
t2 = torch.randn(1,3)
print(t)
>>>tensor([[-0.1856,  1.8894,  1.1288]])
print(t1)
>>>tensor([[-0.6742,  2.0252, -0.6274]])
print(t2)
>>>tensor([[-1.7973, -1.3763,  1.0582]])
# t + 100*(t1*t2)
print(torch.addcmul(t,100,t1,t2))
>>>tensor([[ 120.9984, -276.8339,  -65.2656]])

(4)向上取整ceil | 向下取整floor

import torch
t = torch.randn(1,3)
print(t)
print(t.ceil())
print(t.floor())
>>>tensor([[-0.8639, -0.6445,  2.4636]])
tensor([[-0., -0., 3.]])
tensor([[-1., -1.,  2.]])

(5)将张量限制在指定区间

import torch
t = torch.randn(1,3)
print(t)
print(t.clamp(0,1))
>>>tensor([[ 0.1364,  0.8311, -0.1269]])
tensor([[0.1364, 0.8311, 0.0000]])

(6)指数exp | 对数log | 幂pow

import torch
t = torch.tensor([1,4,9])
print(t)
print(t.exp())
print(t.log())
print(t.pow(2))
>>>tensor([1, 4, 9])
tensor([2.7183e+00, 5.4598e+01, 8.1031e+03])
tensor([0.0000, 1.3863, 2.1972])
tensor([ 1, 16, 81])

(7)逐元素乘法mul* | 取反neg

import torch
t = torch.tensor([2,4,8])
print(t)
print(t.mul(2))
print(t*2)
print(t.neg())
>>>tensor([2, 4, 8])
tensor([ 4,  8, 16])
tensor([ 4,  8, 16])
tensor([-2, -4, -8])

(8)激活函数sigmoid / tanh / softmax

import torch
t = torch.tensor([2.,4.,8.])
print(t)
print(t.sigmoid())
print(t.tanh())
print(t.softmax(0))
>>>tensor([2., 4., 8.])
tensor([0.8808, 0.9820, 0.9997])
tensor([0.9640, 0.9993, 1.0000])
tensor([0.0024, 0.0179, 0.9796])

(9)取符号sign | 开根号sqrt

import torch
t = torch.tensor([2,-4,8])
print(t)
print(t.sign())
print(t.sqrt())
>>>tensor([ 2, -4,  8])
tensor([ 1, -1,  1])
tensor([1.4142,    nan, 2.8284])

6.归并操作

(1)cumprod(t,axis)在指定维度对t进行累积

import torch
t = torch.linspace(0,10,6)
t = t.view((2,3))
print(t)
print(t.cumprod(0))
print(t.cumprod(1))
>>>tensor([[ 0.,  2.,  4.],
        [ 6.,  8., 10.]])
tensor([[ 0.,  2.,  4.],
        [ 0., 16., 40.]])
tensor([[  0.,   0.,   0.],
        [  6.,  48., 480.]])

(2)cumsum(t,axis)在指定维度对t进行累加

import torch
t = torch.linspace(0,10,6)
t = t.view((2,3))
print(t)
print(t.cumsum(0))
print(t.cumsum(1))
>>>tensor([[ 0.,  2.,  4.],
        [ 6.,  8., 10.]])
tensor([[ 0.,  2.,  4.],
        [ 6., 10., 14.]])
tensor([[ 0.,  2.,  6.],
        [ 6., 14., 24.]])

(3)dist(a,b,p=2)返回a,b之间的p阶范数

import torch
t = torch.randn(2,3)
t1 = torch.randn(2,3)
print(t)
print(t1)
print(torch.dist(t,t1,2))
>>>tensor([[ 0.7374,  0.3365, -0.3164],
        [ 0.9939,  0.9986, -1.8464]])
tensor([[-0.4015,  0.7628,  1.5155],
        [-1.9203, -1.0317, -0.0433]])
tensor(4.5498)

(4)mean\median 均值\中位数

import torch
t = torch.randn(2,3)
print(t)
print(t.mean())
print(t.median())
>>>tensor([[-1.2806, -0.2002, -1.6772],
        [-1.0748,  0.9528, -0.9231]])
tensor(-0.7005)
tensor(-1.0748)

(5)std\var 标准差\方差

import torch
t = torch.randn(2,3)
print(t)
print(t.std())
print(t.var())
>>>tensor([[-0.3008,  0.5051, -0.3573],
        [ 0.6127,  0.5265, -0.2748]])
tensor(0.4727)
tensor(0.2234)

(6)norm(t,p=2)返回t的p阶范数

import torch
t = torch.randn(2,3)
print(t)
print(t.norm(2))
>>>tensor([[-1.4880, -0.6627,  0.0032],
        [-2.0794, -0.4204,  0.7097]])
tensor(2.7673)

(7)prod(t) \ sum(t) 返回t所有元素的积 \ 和

import torch
t = torch.randn(2,3)
print(t)
print(t.prod())
print(t.sum())
>>>tensor([[ 1.0360,  1.5088,  2.3022],
        [-0.9142,  1.9266, -0.8202]])
tensor(5.1986)
tensor(5.0393)

7.比较操作

(1)eq 比较Tensor是否相等,支持broadcast

import torch
t = torch.tensor([[1,2,3],[4,5,6]])
t1 = torch.tensor([[1,2,3],[4,5,6]])
print(t)
print(t1)
print(t.eq(t1))
>>>tensor([[1, 2, 3],
        [4, 5, 6]])
tensor([[1, 2, 3],
        [4, 5, 6]])
tensor([[True, True, True],
        [True, True, True]])

(2)equal 比较Tensor是否有相同的shape与值

import torch
t = torch.tensor([[1,2,3],[4,5,6]])
t1 = torch.tensor([[1,2,3],[4,5,6]])
t2 = torch.tensor([1,2,3,4,5,6])
print(t)
print(t1)
print(t2)
print(t.equal(t1))
print(t.equal(t2))
>>>tensor([[1, 2, 3],
        [4, 5, 6]])
tensor([[1, 2, 3],
        [4, 5, 6]])
tensor([1, 2, 3, 4, 5, 6])
True
False

(3)ge\le\gt\lt 大于\小于\大于等于\小于等于

import torch
t = torch.tensor([[1,2,3],[4,5,6]])
t1 = torch.tensor([[3,2,1],[6,5,4]])
print(t)
print(t1)
>>>tensor([[1, 2, 3],
        [4, 5, 6]])
tensor([[3, 2, 1],
        [6, 5, 4]])
print(t.ge(t1))
>>>tensor([[False,  True,  True],
        [False,  True,  True]])

print(t.le(t1))
>>>tensor([[ True,  True, False],
        [ True,  True, False]])

print(t.gt(t1))
>>>tensor([[False, False,  True],
        [False, False,  True]])

print(t.lt(t1))
>>>tensor([[ True, False, False],
        [ True, False, False]])

(4)max\min(t,axis) 返回最值,若指定axis,则额外返回下标

import torch
t = torch.tensor([[1,2,3],[4,5,6]])
print(t)
>>>tensor([[1, 2, 3],
        [4, 5, 6]])

print(t.max())
>>>tensor(6)

print(t.max(1))
>>>torch.return_types.max(
values=tensor([3, 6]),
indices=tensor([2, 2]))

print(t.min())
>>>tensor(1)

print(t.min(1))
>>>torch.return_types.min(
values=tensor([1, 4]),
indices=tensor([0, 0]))



(5)topk(t,k,axis) 在指定的axis维上取最高的K个值

import torch
t = torch.tensor([[1,2,3],[4,5,6]])
print(t)
>>>tensor([[1, 2, 3],
        [4, 5, 6]])

print(t.topk(1,0))
>>>torch.return_types.topk(
values=tensor([[4, 5, 6]]),
indices=tensor([[1, 1, 1]]))

print(t.topk(1,1))
>>>torch.return_types.topk(
values=tensor([[3],
        	   [6]]),
indices=tensor([[2],
        	    [2]]))

print(t.topk(2,0))
>>>torch.return_types.topk(
values=tensor([[4, 5, 6],
        	   [1, 2, 3]]),
indices=tensor([[1, 1, 1],
        	    [0, 0, 0]]))

print(t.topk(2,1))
>>>torch.return_types.topk(
values=tensor([[3, 2],
        	   [6, 5]]),
indices=tensor([[2, 1],
        	    [2, 1]]))

8.矩阵操作

(1)dot(t1,t2) 计算张量(1D)的内积/点积

import torch
t = torch.tensor([3,4])
t1 = torch.tensor([2,3])
print(t)
print(t1)
print(t.dot(t1))
>>>tensor([3, 4])
tensor([2, 3])
tensor(18)

(2)mm(mat1,mat2) \ bmm(batch1,batch2) 计算矩阵乘法/含batch的3D矩阵乘法

import torch
t = torch.randint(10,(2,3))
t1 = torch.randint(6,(3,4))
print(t)
print(t1)
print(t.mm(t1))
>>>tensor([[9, 3, 9],
        [0, 3, 8]])
tensor([[3, 0, 0, 1],
        [4, 5, 5, 3],
        [2, 0, 1, 4]])
tensor([[57, 15, 24, 54],
        [28, 15, 23, 41]])

t = torch.randint(10,(2,2,3))
t1 = torch.randint(6,(2,3,4))
print(t)
print(t1)
print(t.bmm(t1))
>>>tensor([[[7, 4, 0],
         [5, 5, 1]],

        [[1, 4, 1],
         [3, 3, 6]]])
tensor([[[0, 3, 2, 5],
         [3, 2, 1, 3],
         [3, 3, 4, 5]],

        [[3, 5, 2, 3],
         [2, 1, 0, 5],
         [5, 1, 2, 2]]])
tensor([[[12, 29, 18, 47],
         [18, 28, 19, 45]],

        [[16, 10,  4, 25],
         [45, 24, 18, 36]]])

(3)mv(t1,v1) 计算矩阵与向量乘法

import torch
t = torch.randint(10,(2,2))
t1 = torch.tensor([1,2])
print(t)
print(t1)
print(t.mv(t1))
>>>tensor([[0, 7],
        [5, 5]])
tensor([1, 2])
tensor([14, 15])

(4)t 转置

import torch
t = torch.randint(10,(2,2))
print(t)
print(t.t())
>>>tensor([[5, 3],
        [0, 8]])
tensor([[5, 0],
        [3, 8]])

(5)svd(t) 计算t的SVD分解

import torch
t = torch.tensor([[1.,2.],[3.,4.]])
print(t)
>>>tensor([[1., 2.],
        [3., 4.]])

print(t.svd())
>>>torch.return_types.svd(
U=tensor([[-0.4046, -0.9145],
        [-0.9145,  0.4046]]),
S=tensor([5.4650, 0.3660]),
V=tensor([[-0.5760,  0.8174],
        [-0.8174, -0.5760]]))

9.PyTorch与Numpy的比较

操作类别NumpyPyTorch
数据类型np.ndarraytorch.Tensor
np.float32torch.float32;torch.float
np.float64torch.float64;torch.double
np.int64torch.int64;torch.long
从已有数据构建np.arrat([1,2],dtype=np.float16)torch.tensor([1,2],dtype.float16)
x.copy()x.clone()
np.concatenatetorch.cat
线性代数np.dottorch.mm
属性x.ndimx.dim
x.sizex.nelement
形状操作x.reshapex.reshape;x.view
x.flattenx.view(-1)
类型转换np.floor(x)torch.floor(x);x.floor()
比较np.lessx.lt
np.less_equal ; np.greaterx.le / x.gt
np.greate_equal / np.equal / np.not_equalx.ge / x.eq / x.ne
随机种子np.random.seedtorch.manual_seed

相关推荐

【pyTorch学习笔记①】Numpy基础·上篇
【pyTorch学习笔记②】Numpy基础·下篇
【pyTorch学习笔记③】PyTorch基础·上篇

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/17101.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

对偶问题和KKT条件

KKT条件 对于不等式约束优化问题 min ⁡ f ( x ) s . t . g ( x ) ≤ 0 \min\quad f(x)\\ {\rm s.t.}\quad g(x)\leq 0 minf(x)s.t.g(x)≤0 拉格朗日函数为 L ( x , λ ) f ( x ) λ g ( x ) L(x,\lambda)f(x)\lambda g(x) L(x,λ)f(x)λg(x) 。 KKT条件包括 拉格朗日函…

工厂方法模式

// 简单工厂模式 #include <iostream> #include <string>// 抽象产品类 class Product { public:virtual ~Product() {}virtual std::string getName() 0; };// 具体产品类A class ProductA : public Product { public:std::string getName() {return "Produ…

(抄送列表,年会抽奖)笔试强训

博主简介&#xff1a;想进大厂的打工人博主主页&#xff1a;xyk:所属专栏: JavaEE初阶 目录 文章目录 一、[编程题]抄送列表 二、[编程题]年会抽奖 一、[编程题]抄送列表 链接&#xff1a;抄送列表__牛客网 来源&#xff1a;牛客网 题目&#xff1a; NowCoder每天要处理许多邮…

ChatGPT实现服务器体验沙箱

服务器体验沙箱 IT 人员在学习一门新技术时&#xff0c;第一个入门门槛通常都是"如何在本地安装并成功运行"。因此&#xff0c;很多技术的官网都会通过沙箱技术&#xff0c;提供在线试用的 playground 或者按步模拟的 tour。让爱好者先在线尝试效果是否满足预期&…

MATLAB函数封装2:QT调用封装函数

在利用MATLAB进行封装函数之后&#xff0c;最主要的目的是对函数进行调用&#xff0c;能够对矩阵运算和其他算法的运行进行快捷处理。 在有了MATLAB函数之后封装成DLL文件之后&#xff0c;在QT中添加动态链接库&#xff0c;就可以实现函数的调用过程&#xff0c;这个过程相对简…

选择云原生是企业进行技术变革的必经之路

前言 众所周知&#xff0c;云计算领域的蓬勃发展&#xff0c;让越来越多的企业将自己的业务搬到云上&#xff0c;上云已经成为大部分企业的首选操作。无论是头部的中大型企业&#xff0c;还是普通的微小企业&#xff0c;企业业务是亘古不变的核心&#xff0c;这关系着企业的命脉…

7.0、Java继承与多态 - 多态的特性

7.0、Java继承与多态 - 多态的特性 面向对象的三大特征&#xff1a;封装性、继承性、多态性&#xff1b; extends继承 或者 implements实现&#xff0c;是多态性的前提&#xff1b; 用学生类创建一个对象 - 小明&#xff0c;他是一个 学生&#xff08;学生形态&#xff09;&…

彻底告别手动配置任务,魔改xxl-job!

分析 改造 1、接口调用 2、创建新注解 3、自动注册核心 4、自动装配 测试 测试后 XXL-Job是一款非常优秀的任务调度中间件&#xff0c;其轻量级、使用简单、支持分布式等优点&#xff0c;被广泛应用在我们的项目中&#xff0c;解决了不少定时任务的调度问题。不仅如此&a…

TIM-定时器——STM32

TIM-定时器——STM32 TIM(Timer)定时器 定时器可以对输入的时钟进行计数&#xff0c;并在计数值达到设定值时触发中断 16位计数器、预分频器、自动重装寄存器的时基单元&#xff0c;在72MHz计数时钟下可以实现最大59.65s的定时 不仅具备基本的定时中断功能&#xff0c;而且还包…

Mybatis方式完成CRUD操作

Mybatis方式完成CRUD操作 文章目录 Mybatis方式完成CRUD操作1、java以Mybatis方式操作DB1.1、配置数据源-创建 resources/mybatis-config.xml1.2、创建java bean-Monster1.3、配置Mapper接口声明方法1.4、配置xxMapper&#xff0c;完成SQL配置,实现CRUD操作1.5、Test测试 2、需…

jvm调优策略

jvm调优主要是内存管理方面的调优&#xff0c;包括各个代的大小&#xff0c;GC策略等。 代大小调优 JVM 中最大堆大小有三方面限制&#xff1a;相关操作系统的数据模型&#xff08;32-bt还是64-bit&#xff09;限制&#xff1b;系统的可用虚拟内存限制&#xff1b;系统的可用物…

第三十二章 Unity Mecanim动画系统(上)

在上一章节中&#xff0c;我们介绍了Unity的旧版动画系统&#xff0c;本章节来介绍新版的Mecanim动画系统。新版的Mecanim动画系统实际是对旧版动画系统的升级。新版的Mecanim动画系统仍然是建立在动画片段的基础上的&#xff0c;只不过它给我们提供了一个可视化的窗口来编辑动…

R语言的Meta分析【全流程、不确定性分析】方法与Meta机器学习

详情点击链接&#xff1a;R语言的Meta分析【全流程、不确定性分析】方法与Meta机器学习 Meta分析的选题与文献检索 Meta分析Meta分析的选题策略文献检索数据库精确检索策略&#xff0c;如何检索全、检索准文献的管理与清洗&#xff0c;如何制定文献纳入排除标准文献数据获取技…

搭建网站使用轻量云服务器怎么样?

​  搭建网站实际上可以从轻量云服务器租用中受益匪浅。如果您正在为个人网站寻找更多的低成本和轻运维&#xff0c;您可以考虑将轻量云服务器作为一个可行的选择。它提供独享资源、独立的IP地址、专属防火墙以及比传统虚拟主机更好的安全性能。本文将介绍轻量云服务器对建站…

【操作系统OS】学习笔记:第一章 操作系统基础【哈工大李治军老师】

基于本人观看学习 哈工大李治军老师主讲的操作系统课程 所做的笔记&#xff0c;仅进行交流分享。 特此鸣谢李治军老师&#xff0c;操作系统的神作&#xff01; 如果本篇笔记帮助到了你&#xff0c;还请点赞 关注 支持一下 ♡>&#x16966;<)!! 主页专栏有更多&#xff0…

Ubuntu磁盘和目录和文件的相关操作

目录 1、目录的切换 2、查看目录及文件 3、目录的常见操作 4、文件的常见操作 5、查看文件及目录大小 6、命令查看硬盘信息 1、目录的切换 打开终端窗口&#xff08;”ctrlaltt“&#xff09; 一般使用&#xff08;”pwd“&#xff09;显示当前所在的目录 比如&#x…

Flutter学习之旅 -网格布局

GridView列表三种形式 可以通过GridView.count实现网格布局 /* 格式: GridView.count(crossAxisCount: 一行显示数量,children: [component(),...],) */ class MyHomePage extends StatelessWidget {const MyHomePage({Key? key}) : super(key: key);overrideWidget build(B…

C++每日一练:小艺照镜子(详解分治法)

文章目录 前言一、题目二、解题1.分析 总结 前言 大过节的&#xff0c;不想去看人后脑勺&#xff0c;就做点题来玩。挑了小艺照镜子&#xff0c;百分通过~ 提示&#xff1a;以下是本篇文章正文内容&#xff0c;下面案例可供参考 一、题目 题目名称&#xff1a; 小艺照镜子 …

【Linux】生产者消费者模型

目录 一、生产者消费者模型 1、生产者消费者模型的概念 2、生产者、消费者之间的关系 3、生产者和消费者的特点 二、基于BlockingQueue的生产者消费者模型&#xff08;条件变量控制同步与互斥&#xff09; 1、一个生产线程和一个消费线程完成的计算任务 1.1BlockQueue.h…

Kubernetes服务搭建[配置-部署](Kubeadm)

文章目录 **[1 — 7] ** [ 配置K8S主从集群前置准备操作 ]一&#xff1a;主节点操作 查看主机域名->编辑域名1.1 编辑HOST 从节点也做相应操作1.2 从节点操作 查看从节点102域名->编辑域名1.3 从节点操作 查看从节点103域名->编辑域名 二&#xff1a;安装自动填充&…
最新文章