1. python中有乙個zfill方法用來給字串前面補0,非常有用
n
=
"123"
s
=
n.zfill(
5
)
assert
s
=
=
"00123"
zfill()也可以給負數補0
n
=
"-123"
s
=
n.zfill(
5
)
assert
s
=
=
"-0123"
對於純數字,我們也可以通過格式化的方式來補0
view source
print?
n
=
123
s
=
"%05d"
%
n
assert
s
=
=
"00123"
2. int, string 之間的轉換
astr = str(a) # a is a int
i = int(astr)
3. tensor, numpy的array之間的轉換
b = a.numpy() #a為tensor
b = torch.from_numpy(a) #a為numpy的array
參考: pytorch函式或python函式
比較官方的python 3 教程 參考迭代工具 product zip 使用方法.python range 函式用法.如product ab range 3 相當於是組合兩個list,list1 ab list2 0,1,2 將兩部分可迭代物件,一一組合起來.假設兩個可迭代物件,第乙個為n維,第二個...
201208 PyTorch求解矩陣正交基
orth is obtained from u in the singular value decomposition,u,s svd a,econ if r rank a the first r columns of uform an orthonormal basis for the range...
PyTorch 實現異或XOR運算
1.異或運算 2.實現 1 利用pytorch解決xor問題 2import torch 3import torch.nn as nn 4import torch.nn.functional as f 5import torch.optim as optim 6import numpy as np ...