我正在寻找一个超级数字正交函数.它应该具有以下三个属性:
另外,它应该是:
有人知道有这样一个函数的库吗?即使四个属性中的两个或三个也不会好.
我正在使用Python和SciPy,所以如果它已经与Python一起使用,那就是奖励.(但是我也可以编写胶水代码,让它在必要时调用我的被积函数.)
我正在为一个项目使用GCC SIMD向量扩展,一切都很好但是转换,它们只是重置向量的所有组件.
在手动状态:
可以从一种向量类型转换为另一种向量类型,前提是它们具有相同的大小(实际上,您也可以将向量转换为相同大小的其他数据类型).
这是一个简单的例子:
#include <stdio.h>
typedef int int4 __attribute__ (( vector_size( sizeof( int ) * 4 ) ));
typedef float float4 __attribute__ (( vector_size( sizeof( float ) * 4 ) ));
int main()
{
int4 i = { 1 , 2 , 3 , 4 };
float4 f = { 0.1 , 0.2 , 0.3 , 0.4 };
printf( "%i %i %i %i\n" , i[0] , i[1] , i[2] , i[3] );
printf( "%f %f %f …Run Code Online (Sandbox Code Playgroud) 我有一个M x N矩阵.我想N用M x M矩阵乘以每列.以下是循环中的这个,但我不知道如何对其进行矢量化.
u=repmat(sin(2*pi*f*t),[n 1]);
W = rand(n);
answer = size(u);
for i=1:size(u,2)
answer(:,i) = W*u(:,i);
end
Run Code Online (Sandbox Code Playgroud) 我的数据有一列,我正在尝试使用行中每个"/"之后的内容创建其他列.以下是数据的前几行:
> dput(mydata)
structure(list(ALL = structure(c(1L, 4L, 4L, 3L, 2L), .Label = c("/
ca/put/sent_1/fe.gr/eq2_on/eq2_off",
"/ca/put/sent_1/fe.gr/eq2_on/eq2_off/cbr_LBL", "/ca/put/sent_1/fe.g
r/eq2_on/eq2_off/cni_at.p3x.4",
"/ca/put/sent_1/fe.gr/eq2_on/eq2_off/hi.on/hi.ov"), class = "factor
")), .Names = "ALL", class = "data.frame", row.names = c(NA,
-5L))
Run Code Online (Sandbox Code Playgroud)
如果变量出现在行中,结果应该如此(数据框)在新列中带有"1",否则为"0":
> dput(Result)
structure(list(ALL = structure(c(1L, 4L, 5L, 3L, 2L), .Label = c("/ca
/put/sent_1/fe.gr/eq2_on/eq2_off",
"/ca/put/sent_1/fe.gr/eq2_on/eq2_off/cbr_LBL", "/ca/put/sent_1/fe.gr/
eq2_on/eq2_off/cni_at.p3x.4",
"/ca/put/sent_1/fe.gr/eq2_on/eq2_off/hi.on/hi.ov", "/ca/put/sent_1fe.
gr/eq2_on/eq2_off/hi.on/hi.ov"
), class = "factor"), ca = c(1L, 1L, 1L, 1L, 1L), put = c(1L,
1L, 1L, 1L, 1L), sent_1 = c(1L, 1L, 1L, 1L, 1L), fe.gr = c(1L, …Run Code Online (Sandbox Code Playgroud) 我有一个函数,它接收2个以上的变量
例如.
testFunction = @(x1, x2, x3, x4) x1.*x2.*x3.*x4;
testFunction2 = @(x1, x2, x3) sin(x1.*x2.^x3);
Run Code Online (Sandbox Code Playgroud)
有没有可用的功能bsxfun允许单个扩展功能有多于2个输入?
的例子 bsxfun
binaryTestFunction = @(x1, x2) x1.*x2;
x1 = 9*eye(10);
x2 = 3*ones(10,1);
A = bsxfun(binaryTestFunction , x1 , x2);
Run Code Online (Sandbox Code Playgroud)
扩展x2向量中的单例维度.
bsxfun比repmat更快,也是高度迭代的,因此我想知道单例扩展testFunction是否可行.
假设我有:
A = rand(1,10,3);
B = rand(10,16);
Run Code Online (Sandbox Code Playgroud)
我想得到:
C(:,1) = A(:,:,1)*B;
C(:,2) = A(:,:,2)*B;
C(:,3) = A(:,:,3)*B;
Run Code Online (Sandbox Code Playgroud)
我能以某种方式将它乘以一行,以便更快吗?
如果我像这样创建新的张量b怎么办?
for i = 1:3
b(:,:,i) = B;
end
Run Code Online (Sandbox Code Playgroud)
我可以乘以A和b来获得相同的C但速度更快吗?通过上面的循环创建b所花费的时间并不重要,因为我将需要C用于许多不同的As而B保持不变.
performance matlab vectorization multiplication multidimensional-array
代码如下:
import numpy as np
X = np.array(range(15)).reshape(5,3) # X's element value is meaningless
flag = np.random.randn(5,4)
y = np.array([0, 1, 2, 3, 0]) # Y's element value in range(flag.shape[1]) and Y.shape[0] equals X.shape[0]
dW = np.zeros((3, 4)) # dW.shape equals (X.shape[1], flag.shape[1])
for i in xrange(5):
for j in xrange(4):
if flag[i,j] > 0:
dW[:,j] += X[i,:].T
dW[:,y[i]] -= X[i,:].T
Run Code Online (Sandbox Code Playgroud)
为了更有效地计算dW,如何对此for循环进行矢量化?
假设我有两个numpy数组,A形状(d, f)和I形状(d,)包含索引0..n,例如
I = np.array([0, 0, 1, 0, 2, 1])
A = np.arange(12).reshape(6, 2)
Run Code Online (Sandbox Code Playgroud)
我要寻找一个快速的方式,使削减,特别是sum,mean和max,在所有切片A[I == i, :]; 一个慢版本
results = np.zeros((I.max() + 1, A.shape[1]))
for i in np.unique(I):
results[i, :] = np.mean(A[I == i, :], axis=0)
Run Code Online (Sandbox Code Playgroud)
在这种情况下给出
results = [[ 2.66666667, 3.66666667],
[ 7. , 8. ],
[ 8. , 9. ]])
Run Code Online (Sandbox Code Playgroud)
编辑:我根据Divakar的回答和之前的海报(已删除)pandas回答做了一些时间安排.
时间码:
from __future__ import division, …Run Code Online (Sandbox Code Playgroud) 我是一个SIMD初学者,我读过这个文章的话题(因为我使用AVX2兼容机).
现在,我已经阅读了这个问题来检查你的指针是否对齐.
我正在用这个玩具示例测试它main.cpp:
#include <iostream>
#include <immintrin.h>
#define is_aligned(POINTER, BYTE_COUNT) \
(((uintptr_t)(const void *)(POINTER)) % (BYTE_COUNT) == 0)
int main()
{
float a[8];
for(int i=0; i<8; i++){
a[i]=i;
}
__m256 evens = _mm256_set_ps(2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0);
std::cout<<is_aligned(a, 16)<<" "<<is_aligned(&evens, 16)<<std::endl;
std::cout<<is_aligned(a, 32)<<" "<<is_aligned(&evens, 32)<<std::endl;
}
Run Code Online (Sandbox Code Playgroud)
然后编译它icpc -std=c++11 -o main main.cpp.
最终的印刷是:
1 1
1 1
Run Code Online (Sandbox Code Playgroud)
但是,如果我在4张照片之前加上3行:
for(int i=0; i<8; i++)
std::cout<<a[i]<<" ";
std::cout<<std::endl;
Run Code Online (Sandbox Code Playgroud)
这是结果:
0 1 2 3 …Run Code Online (Sandbox Code Playgroud) 如何使用Numpy对此for循环进行向量化?
count=0
arr1 = np.random.rand(184,184)
for i in range(arr1.size[0]):
for j in range(arr1.size[1]):
if arr1[i,j] > 0.6:
count += 1
print count
Run Code Online (Sandbox Code Playgroud)
我试过了:
count=0
arr1 = np.random.rand(184,184)
mask = (arr1>0.6)
indices = np.where(mask)
print indices , len(indices)
Run Code Online (Sandbox Code Playgroud)
我期望len(指数)给予计数,但事实并非如此.请给我任何建议.