- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个大小为 3xn
的 numpy 数组(edges
),它恰好包含两行,其中该行的前两个元素可能匹配,也可能不匹配匹配。我正在根据这个标准计算一些东西。我的基于 for 循环的代码遵循这些原则
mat = np.zeros((edges.shape[0],2),dtype=np.int64)
counter = 0;
for i in range(edges.shape[0]):
for j in range(i+1,edges.shape[0]):
if edges[i,0]==edges[j,0] and edges[i,1]==edges[j,1] and edges[i,2] != edges[j,2]:
mat[2*counter,0] = i % nof
mat[2*counter,1] = i // nof
mat[2*counter+1,0] = j % nof
mat[2*counter+1,1] = j // nof
counter +=1
break
其中nof
是一个特定的数字。如何使用 numpy 加速此代码?我无法使用 np.unique ,因为此代码需要唯一性以及非唯一性检查。
例如,给定:
edges = np.array([
[1,2,13],
[4,5,15],
[5,6,18],
[1,2,12],
[4,5,15],
[5,6,18],
])
其中每行的前两个元素可以在另一行中找到(即它们恰好重复两次)并且nof=1
,上面的代码给出以下结果
[[0 0]
[0 3]
[0 0]
[0 0]]
最佳答案
我还没有了解您如何设置mat
,但我怀疑前两列的词法排序可能会有所帮助:
In [512]: edges = np.array([
...: [1,2,13],
...: [4,5,15],
...: [5,6,18],
...: [1,2,12],
...: [4,5,15],
...: [5,6,18],
...: ])
...:
In [513]: np.lexsort((edges[:,1],edges[:,0]))
Out[513]: array([0, 3, 1, 4, 2, 5], dtype=int32)
In [514]: edges[_,:] # sedges (below)
Out[514]:
array([[ 1, 2, 13],
[ 1, 2, 12],
[ 4, 5, 15],
[ 4, 5, 15],
[ 5, 6, 18],
[ 5, 6, 18]])
现在所有匹配的行都在一起。
如果总是有 2 个匹配项,则可以收集这些对并将其重新整形为 2 列数组。
In [516]: sedges[:,2].reshape(-1,2)
Out[516]:
array([[13, 12],
[15, 15],
[18, 18]])
或者,您仍然可以迭代,但不必检查那么远。
<小时/>排序列表上的argsort
返回相反的排序:
In [519]: np.lexsort((edges[:,1],edges[:,0]))
Out[519]: array([0, 3, 1, 4, 2, 5], dtype=int32)
In [520]: np.argsort(_)
Out[520]: array([0, 2, 4, 1, 3, 5], dtype=int32)
In [521]: sedges[_,:]
Out[521]:
array([[ 1, 2, 13],
[ 4, 5, 15],
[ 5, 6, 18],
[ 1, 2, 12],
[ 4, 5, 15],
[ 5, 6, 18]])
关于python - 如何在需要唯一性和非唯一性检查的Python循环中向量化这个循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46125252/
我想使用Tensorflow的transform_graph工具优化图形。我尝试优化 MultiNet 中的图表(以及其他具有类似编码器-解码器架构的)。然而,优化后的图在使用 quantize_we
我试图在 C# 中将图像量化为 10 种颜色,但在绘制量化图像时遇到问题,我已经制作了映射表并且它是正确的,我已经制作了原始图像的副本并且正在更改基于映射表的像素颜色,我使用下面的代码: bm = n
我需要降低UIImage的颜色深度,但是我不知道该怎么做。结果应与在Photoshop中应用索引颜色相同。 我的目标是要具有较低的色深(32色或更低)。也许这是我的错,但我没有找到解决方法。令人惊讶的
我有大量的 numpy 向量,每个形状 (3,) 都有 8 位整数值: vec = np.random.randint(2**8, size=3) 我想通过一些已知的缩减因子将这些向量量化到更小的空间
我正在用 jQuery 编写一个心理学应用程序。我的项目的一部分需要测量用户对声音的 react 时间(用户按下一个键)。因此,我需要在调用(&时间戳)声音文件和实际开始播放之间的延迟尽可能小地播放声
最近,我开始使用 Tensorflow + Keras 创建神经网络,我想尝试 Tensorflow 中提供的量化功能。到目前为止,使用 TF 教程中的示例进行试验效果很好,我有这个基本的工作示例(来
使用当前的 Tensorflow quantization ops ,我将如何在推理过程中模拟每 channel 量化?这paper将每层量化定义为 We can specify a single q
我已经卡住了我的模型并获得了 .pb 文件。然后我在 Linux 上使用 tocoConverter 量化我的模型,因为 Windows 不支持它。我有 quantized_model.tflite。
我将 git 用于一个稍微不寻常的目的——它在我写小说时存储我的文本。 (我知道,我知道......令人讨厌。) 我正在尝试跟踪生产力,并想衡量后续提交之间的差异程度。作家代表“作品”的是“文字”,至
quantization有什么区别和 simplification ? 量化是另一种简化方式吗? 在某些情况下使用量化更好吗? 或者我应该同时使用两者? 最佳答案 几何体的总大小由两个因素控制:点数和
扎克伯格说,Llama3-8B还是太大了,不适合放到手机中,有什么办法? 量化、剪枝、蒸馏,如果你经常关注大语言模型,一定会看到这几个词,单看这几个字,我们很难理解它们都干了些什么,但
相对于
我正在将一些我无法控制的 XML 转换为 XHTML。 XML 模式定义了一个 段落标记和 和 用于列表。 我经常在这个 XML 中找到嵌套在段落中的列表。因此,直接转换会导致 s 嵌套在 中s,
我看到过这样的说法:CNN 的更深层次可以学习识别更复杂的特征。这通常附带一张早期过滤器识别直线/简单曲线的图片,以及后期过滤器识别更复杂图案的图片。它具有直观意义:您距离数据越远,您对数据的理解就越
在使用 C++ 的带有 tensorflow lite 的树莓派上,对象检测无法正常工作。我的代码编译并运行,但输出似乎从未得到正确填充。我是否会遗漏任何依赖项或错误地访问结果? 我遵循了以下教程:
如何衡量/量化 Corona SDK 游戏应用中的“迟缓”? 我在我构建的基于 Corona SDK 的物理游戏(使用 Box2D)上寻找旧手机(例如 iPhone 4、Samsung GT-I900
我正在尝试创建一个 Tensorflow 量化模型,以便使用 Coral USB 加速器进行推理。这是我的问题的一个最小的独立示例: import sys import tensorflow as t
我有一个分位数回归模型,其中包含 1 个回归变量和 1 个回归变量。我想假设检验回归量在每个分位数上都相等。我想到的一种方法是在 {0.01,0.02,....,0.99} 上测试所有 tau。但是,
要求做,在 PGM 文件上使用 KMeans 进行 vector 量化(或图像压缩) 图像是 PMG 文件,其中 b = block 大小,k = 次数,t = 迭代,-g = 初始质心 图像是这样的
我是一名优秀的程序员,十分优秀!