- 博客(13)
- 收藏
- 关注
转载 axis的理解和检验
import numpy as np # 产生60个[0,60)的随机整数,维度为3x = np.random.RandomState(5).randint(60, size=[3, 4, 5])print(x.ndim, x.shape, x.size)print("x:\n", x)print("x[0][0]:\n", x[0][0])print("axis=2: \n", np.amax(x, 2))print("x[0]:\n", x[0])print("axis=1: \n.
2021-11-30 01:09:32
103
原创 *号,收集参数,解包
def m(*a): for i in a: print(i) print(a) print(*a) print(len(a))c = m((1,2,3),(4,5,6),(7,8,9))(1, 2, 3)(4, 5, 6)(7, 8, 9)((1, 2, 3), (4, 5, 6), (7, 8, 9))(1, 2, 3) (4, 5, 6) (7, 8, 9)3def m(*a): for i in a: .
2021-04-03 23:49:04
73
原创 用range生成值为序号的字典
a = ['d','e','f']zipped = zip(a,range(len(a)))d = dict(zipped)d{'d': 0, 'e': 1, 'f': 2}
2021-04-03 10:36:03
194
原创 字符串 expend
Python的列表如果对字符串用expend, 会按每个字符添加,append方法把字符串看成一个整体添加到一个列表。expend添加的对象默认是迭代器。f = []g = []b = 'hello'f.extend(b)g.append(b)print(f)print(g)输出:['h', 'e', 'l', 'l', 'o']['hello']...
2021-01-24 17:14:01
160
原创 torch.matmul
import torchx = torch.tensor([[[1, 2, 3, 4], [5, 6, 7, 8], [ 9, 10, 11, 12]], [[-1, -2, -3, -4], [-5, -6, -7, -8], [-9, -10, -11, -12]]])y = torch.tensor([1,1,1])print(x.size(), y.size())print(torch.matm.
2021-01-14 20:57:16
291
原创 torch.max np.max
import torchimport numpy as npnp.random.seed(5)torch.manual_seed(6)a = torch.randn(3,3)print(a)输出:tensor([[-0.4868, -0.6038, -0.5581], [ 0.6675, -0.1974, 1.9428], [-1.4017, -0.7626, 0.6312]])b = torch.max(a,0)print(b)输出:to.
2021-01-01 18:25:44
490
原创 next iter内置函数
a = iter([1,3,4,5,7,8,4])print(next(a))print(next(a))print(next(a))#输出134a = next(iter([1,3,4,5,7,8,4]))print(a)print(a)print(a)#输出111a = next(iter([1,3,4,5,7,8,4]))print(next(iter([1,3,4,5,7,8,4])))print(next(iter([1,3,4,5,7,8,4]).
2021-01-01 13:37:10
107
原创 2020-12-13 transform_invert
import torchvision.transforms as transformsnorm_mean = [0.485, 0.456, 0.406]norm_std = [0.229, 0.224, 0.225]train_transform = transforms.Compose([ transforms.Resize((224, 224)), transforms.RandomOrder([transforms.RandomRotation(15), .
2020-12-13 10:37:02
381
转载 类调用方法 self参数
class TaSt: age = 88 # 类属性 def __init__(self, name): self.name = name # 实例属性 def show(self, b): print(u'实例方法', b) @staticmethod def show2(a): print(u'静态方法',a) @classmethod def add(cls, a): # 第一个参数必须是类本身 print(u'类方法', a).
2020-11-28 00:56:10
562
原创 类方法 cls self 参数
class A:@staticmethoddef a(): #静态方法不需要传参数print ("this is a")@classmethoddef b(cls): #类方法的第一个参数 习惯写成cls,打印出来是类print(cls)print ("this is b")def c(self): #第一个参数,习惯写成self 表示实例化后的对象,打印出来是对象print(self)print ("this is c")testa = A(...
2020-11-27 22:56:24
360
原创 torch.stack 理解
import numpy as npimport torcharr1 = np.array([[1, 2, 3], [4, 5, 6]])arr2 = np.array([[7, 8, 9], [5, 4, 3]])c = torch.from_numpy(arr1)d = torch.from_numpy(arr2)t_stack2 = torch.stack([c,d,d], dim=2)print(t_stack2)在第2维上进行数据拼接tensor([[[1, 7, 7],.
2020-11-21 22:23:38
150
原创 shape 和 reshape区别
import numpy as npb = np.arange(15)b.shape=(3,5)print(b) import numpy as npb = np.arange(15)a = b.reshape(3,5)print(a) 指定行数后,列数用-1,列数可以自动进行计算 import numpy as npb = np.aran...
2018-07-29 18:27:07
1317
原创 __del__魔法方法
class C: count = 0 def __init__(self): C.count += 1 def __del__(self): C.count -= 1a = C()b = C()c = ad = ae = a
2016-09-09 22:29:22
270
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人