小编Chr*_*ris的帖子

Matlab和numpy/scipy中的FFT给出不同的结果

我正在尝试重新实现其中一个matlab工具箱.他们在那边使用fft.当我对相同的数据执行相同的操作时,我会得到与matlab不同的结果.看看:

MATLAB:

Msig =

 0     0     0     0
 0     0     0     0
 0     0     0     0
 0     0     0     0
 0     1     0     0
 0     0     0     0

fft(Msig.')

Columns 1 through 4

    0                  0                  0                  0          
    0                  0                  0                  0          
    0                  0                  0                  0          
    0                  0                  0                  0          

Columns 5 through 6

 1.0000                  0          
      0 - 1.0000i        0          
-1.0000                  0          
      0 + 1.0000i        0    
Run Code Online (Sandbox Code Playgroud)

PYTHON:

Msig=
array([[ 0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.],
       [ …
Run Code Online (Sandbox Code Playgroud)

python matlab numpy fft scipy

13
推荐指数
1
解决办法
6471
查看次数

使用 python/scipy 进行 voronoi 和 lloyd 松弛

如何使用 Qhull 确定哪些 voronoi 单元(按索引)是“正确的”(由“现有顶点”组成)

我正在尝试使用 LLoyds 算法和由 scipy.spatial Voronoi(它是 Qhull 的包装器)生成的输入来执行约束松弛。

在代码方面,它看起来像:

points = [n  for n in itertools.product(xrange(3),xrange(3))]
vor = Voronoi(points)

vor2 = lloyd(vor) # my relaxation function  - not relevant to the question
Run Code Online (Sandbox Code Playgroud)

代码生成的输出图看起来不错(见下文),但 vor 结构中的数据不足以执行劳埃德松弛。这是因为我应该只移动有效 voronoi 单元格内的点(图像中的 #4)。另一个应该保持原样。Qhull 弄乱了点/区域的顺序,所以我无法估计哪个区域属于哪个点。

这是问题的说明:

print vor.vertices
#[[ 0.5  0.5]
# [ 1.5  0.5]
# [ 0.5  1.5]
# [ 1.5  1.5]]

print vor.regions  
# [[], [-1, 0], [-1, 1], [1, -1, 0], [3, -1, 2], [-1, 3], [-1, 2], [3, …
Run Code Online (Sandbox Code Playgroud)

python voronoi scipy qhull

5
推荐指数
1
解决办法
2483
查看次数

python赋值给循环中的元素列表

这是一个有效的python行为吗?我认为最终结果应该是[0,0,0]并且id()函数应该在每次迭代时返回相同的值.如何使它成为pythonic,而不是使用枚举或范围(len(bar))?

bar = [1,2,3]
print bar
for foo in bar:
    print id (foo)
    foo=0
    print id(foo)
print bar
Run Code Online (Sandbox Code Playgroud)

输出:

[1, 2, 3]
5169664
5169676
5169652
5169676
5169640
5169676
[1, 2, 3]
Run Code Online (Sandbox Code Playgroud)

python loops list object instance

4
推荐指数
1
解决办法
4万
查看次数

编译openGL + GLSL给出了未定义的引用

我试图从互联网上编译这一段代码,我的失败是悲惨的.似乎缺少opengl libs - 但它们在那里 - 我检查过.过剩与过剩相关.

系统是Ubuntu 12.04,glxinfo确认视频适配器是openGL 2.1

这是Makefile:

all: ljus
ljus: ljus.c glsl_shader.c calculation.c calculation.h pyramid_func.c
gcc -std=gnu99 -Wall -o ljus -I. -lz -lglut -lGL -lGLU ljus.c 
Run Code Online (Sandbox Code Playgroud)

我试图将不同的路径传递给链接器,但没有成功.我究竟做错了什么?

PS这里是'make'输出(相当长 - 抱歉):

/tmp/cc0mDnPf.o: In function `glslCreateProgram':
ljus.c:(.text+0x4f): undefined reference to `glCreateProgramObjectARB'
/tmp/cc0mDnPf.o: In function `glslAttachShaderFromMemory':
ljus.c:(.text+0x118): undefined reference to `glCreateShaderObjectARB'
ljus.c:(.text+0x13c): undefined reference to `glShaderSourceARB'
ljus.c:(.text+0x147): undefined reference to `glCompileShaderARB'
ljus.c:(.text+0x15b): undefined reference to `glAttachObjectARB'
ljus.c:(.text+0x166): undefined reference to `glDeleteObjectARB'
/tmp/cc0mDnPf.o: In function `glslBindAttribute':
ljus.c:(.text+0x3f1): undefined reference to `glBindAttribLocationARB' …
Run Code Online (Sandbox Code Playgroud)

opengl linker makefile undefined-reference

3
推荐指数
1
解决办法
1万
查看次数

在matlab和numpy中ifft给出不同的结果

我有另一个问题.非常类似于我已经问过的另一个(并得到很大的帮助 - 再次感谢).不幸的是,其他线程的解决方案在这里不起作用:(http://stackoverflow.com/questions/8680909/fft-in-matlab-and-numpy-scipy-give-different-results)

现在是关于ifft:

  # i have an array 'aaa' of shape (6,) such as:
  for i in aaa:  print i
  ...

 (1.22474487139+0j)
 (-0.612372435696-1.06066017178j)
 (-0.612372435696+1.06066017178j)
 (1.22474487139+0j)
 (-0.612372435696-1.06066017178j)
 (-0.612372435696+1.06066017178j)

  #when i perform np.ifft the result is:
 np.fft.ifft(aaa)

 array([  1.48029737e-16 +1.48029737e-16j,
    -8.26024733e-17 -1.72464044e-16j,
     1.22474487e+00 -3.94508649e-16j,
     3.70074342e-17 -2.96059473e-16j,
    -2.22044605e-16 +2.46478913e-16j,   4.55950391e-17 +4.68523518e-16j])

  ###################################################################
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  % BUT IN MATLAB 
  % the same array...

  aaa =

  1.2247          
 -0.6124 - 1.0607i
 -0.6124 + 1.0607i
  1.2247          
 -0.6124 - 1.0607i
 -0.6124 + 1.0607i

 % ...gives the result:
 ifft(aaa) …
Run Code Online (Sandbox Code Playgroud)

python matlab fft ifft

0
推荐指数
1
解决办法
1861
查看次数

haskell中IO句柄的多行内容不显示任何内容

我一直在试验Haskell.我正在尝试编写一个Web爬虫,我需要使用外部curl二进制文件(由于一些代理设置,curl需要有一些特殊的参数,似乎不可能/很难在haskell代码中设置,所以我宁愿只是传递它作为命令行选项.但这是另一个故事...)

在底部的代码中,如果我更改标记的行curl而不是curl --help输出渲染正确并给出:

"curl: try 'curl --help' or 'curl --manual' for more information
" 
Run Code Online (Sandbox Code Playgroud)

否则字符串为空 - 因为`curl --help'响应是多行的.我怀疑在haskell中,每个新行清除缓冲区.(同样适用于其他简单的shell命令,如lsls -l等)

我如何解决它?

代码:

import System.Process
import System.IO
main = do
    let sp = (proc "curl --help"[]){std_out=CreatePipe} -- *** THIS LINE ***
    (_,Just out_h,_,_)<- createProcess sp
    out <-hGetContents out_h
    print out
Run Code Online (Sandbox Code Playgroud)

io haskell createprocess

0
推荐指数
1
解决办法
66
查看次数