
numpy
「已注销」
这个作者很懒,什么都没留下…
展开
-
Numpy与pytorch对比记忆
1 改变类型numpy:array.astype()torch: tensor.type()import numpy as npimport torchif __name__=="__main__": nn = np.array(1) tt = torch.tensor(1) nn.astype(dtype=np.long) nn.astype(dtype=np.int32) tt.float() tt.type(dtype=torch.flo原创 2021-03-04 18:38:48 · 190 阅读 · 1 评论 -
【numpy】np.random.choice
np.random.choice(a, size=None, replace=True, p=None)#a为一维数组或者int,size默认None,此时返回一个值,也可以为int或者tuple,replace=True为有放回的选择,可能出现重复,p为概率列表,之和应该为1.Parameters: a : 1-D array-like or int If an ndarray, a random sample is generated from its elements.原创 2021-02-01 15:34:27 · 273 阅读 · 0 评论 -
np.where函数
<1> np.where( condition )输入只有条件数组condition的话,返回的是满足条件的元素索引。1)condition为一维数组,返回值out为一个一维数组索引组成的元组;2)condition为二维数组,返回值out为两个一维数组组成的元组,第一个数组为dim=0(行)的索引,第二个数组为dim=1(列)的索引。condition数组: condition二维数组可以来自于数据数组的比较得到。if __name__=="__main__": x = np原创 2021-02-01 14:51:19 · 3171 阅读 · 1 评论 -
np.diag_indices
if __name__=="__main__":n = np.diag_indices(5)print(n)x = np.arange(0, 25).reshape((5, 5))print(x)print(x[n])#output:(array([0, 1, 2, 3, 4]), array([0, 1, 2, 3, 4]))[[ 0 1 2 3 4] [ 5 6 7 8 9] [10 11 12 13 14] [15 16 17 18 19] [20 21 22原创 2021-02-01 09:57:42 · 1262 阅读 · 0 评论