numpy
文章平均质量分 61
*Lisen
这个作者很懒,什么都没留下…
展开
-
矩阵混乱度(熵值)代码计算
极端混乱度,熵值最大。最大值为log_2(dim),实例的dim为4,索引log_2(4) = 2。极端混乱度,熵值最小,最小值跟矩阵的维度无关,基本都为0。增加混乱度,熵值减小。原创 2024-04-19 14:13:59 · 575 阅读 · 0 评论 -
np.memmap的用法
内存映像文件是一种将磁盘上的非常大的二进制数据文件当做内存中的数组进行处理的方式。NumPy实现了一个类似于ndarray的memmap对象,它允许将大文件分成小段进行读写,而不是一次性将整个数组读入内存。memmap也拥有跟普通数组一样的方法,因此,基本上只要是能用于ndarray的算法就也能用于memmap。使用此子类的另一种方法是自己创建mmap 对象,然后直接使用ndarray .__ new__创建一个ndarray,传递在其’buffer ='参数中创建的对象。磁盘上的文件是只读的。转载 2023-10-31 17:15:49 · 554 阅读 · 0 评论 -
pytorch, numpy利用另一个数组的索引进行重排序,如torch.gather.......
import torchtorch.manual_seed(1)logits = torch.rand(3, 10)label_ids = torch.rand(3, 10)print(logits)print(label_ids)sorted_logits, indices = logits.sort(dim=1)new_label_ids = label_ids.gather(...原创 2019-11-05 17:08:01 · 6485 阅读 · 1 评论