运行amd64构建的Python和扩展有什么好处?(这里为amd64编译了很多扩展.)我有一个i5处理器和Win7 64位,所以看起来它是合适的.但它听起来也像是有缺陷,测试版,不支持等.
它实际上是否提供了性能优势?在哪些方面?我将运行SciPy,NumPy等.我偶尔会遇到32位Python的"内存不足"错误,而我的机器有4 GiB的RAM.
如果不存在64位版本的软件包,是否可以在64位Python基础上安装win32软件包?
是否有基于FFT的2D互相关或卷积函数内置于scipy(或其他流行的库)?
有这样的功能:
scipy.signal.correlate2d
- "实施的直接方法convolveND
对于大数据来说会很慢"scipy.ndimage.correlate
- "使用精确计算(即不是FFT)将数组与给定内核相关联."scipy.fftpack.convolve.convolve
,我真的不明白,但似乎错了numarray有一个correlate2d()
带fft=True
开关的功能,但我猜numarray被折叠成numpy,我无法找到是否包含此功能.
这是一个准系统的例子:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
f = fig.add_subplot(2, 1, 1, projection='3d')
t = fig.add_subplot(2, 1, 2, projection='3d')
# axes
for d in {f, t}:
d.plot([-1, 1], [0, 0], [0, 0], color='k', alpha=0.8, lw=2)
d.plot([0, 0], [-1, 1], [0, 0], color='k', alpha=0.8, lw=2)
d.plot([0, 0], [0, 0], [-1, 1], color='k', alpha=0.8, lw=2)
f.dist = t.dist = 5.2 # 10 is default
plt.tight_layout()
f.set_aspect('equal')
t.set_aspect('equal')
r = 6
f.set_xlim3d([-r, r])
f.set_ylim3d([-r, r])
f.set_zlim3d([-r, r])
t.set_xlim3d([-r, …
Run Code Online (Sandbox Code Playgroud) 例如,我有一个ndarray
是:
a = np.array([1, 3, 5, 7, 2, 4, 6, 8])
Run Code Online (Sandbox Code Playgroud)
现在我想a
分成两部分,一部分是所有数字<5,另一部分是> = 5:
[array([1,3,2,4]), array([5,7,6,8])]
Run Code Online (Sandbox Code Playgroud)
当然,我可以遍历a
并创建两个新阵列.但我想知道numpy提供了一些更好的方法吗?
类似地,对于多维数组,例如
array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
[2, 4, 7]])
Run Code Online (Sandbox Code Playgroud)
我想根据第一列<3和> = 3拆分它,结果是:
[array([[1, 2, 3],
[2, 4, 7]]),
array([[4, 5, 6],
[7, 8, 9]])]
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法而不是遍历它?谢谢.
我在对数间隔轴上生成二维数组(例如,使用生成x像素坐标logspace(log10(0.95), log10(2.08), n)
.
我希望使用普通的imshow显示图像,原始分辨率和缩放(我不需要拉伸它 ;数据本身已经是日志缩放),但我想添加刻度,标签,行对数轴上的正确位置.我该怎么做呢?
理想情况下,我可以使用命令行,axvline(1.5)
并且该行将位于正确的位置(左起58%),但如果唯一的方法是在logscale坐标和图像坐标之间手动转换,那也没关系.
对于线性轴,extents=
在调用imshow时使用我想做的事情,但我没有看到用日志轴做同样事情的方法.
例:
from matplotlib.colors import LogNorm
x = logspace(log10(10), log10(1000), 5)
imshow(vstack((x,x)), extent=[10, 1000, 0, 100], cmap='gray', norm=LogNorm(), interpolation='nearest')
axvline(100, color='red')
Run Code Online (Sandbox Code Playgroud)
此示例不起作用,因为extent =仅适用于线性比例,因此当您在100处执行axvline时,它不会出现在中心.我希望x轴显示10,100,1000,并axvline(100)
在100点的中心放一条线,而像素保持相等的间距.
我想为numpy 实现itertools.combinations.根据这个讨论,我有一个适用于一维输入的功能:
def combs(a, r):
"""
Return successive r-length combinations of elements in the array a.
Should produce the same output as array(list(combinations(a, r))), but
faster.
"""
a = asarray(a)
dt = dtype([('', a.dtype)]*r)
b = fromiter(combinations(a, r), dt)
return b.view(a.dtype).reshape(-1, r)
Run Code Online (Sandbox Code Playgroud)
并且输出有意义:
In [1]: list(combinations([1,2,3], 2))
Out[1]: [(1, 2), (1, 3), (2, 3)]
In [2]: array(list(combinations([1,2,3], 2)))
Out[2]:
array([[1, 2],
[1, 3],
[2, 3]])
In [3]: combs([1,2,3], 2)
Out[3]:
array([[1, 2],
[1, 3],
[2, 3]]) …
Run Code Online (Sandbox Code Playgroud) 这曾经起作用,但现在却没有,在Anyonda的IPython 4.2.0和Spyder 2.3.9中.哎呀.
如果我得到IPython配置它看起来是正确的,就好像它正确读取文件:
get_ipython().config
Out[1]:
{'IPCompleter': {'greedy': True},
'IPKernelApp': {'exec_lines': ['%pylab qt']},
'InlineBackendConfig': {},
'InteractiveShell': {'xmode': 'Plain'},
'InteractiveShellApp': {'exec_lines': ['from __future__ import division',
'from __future__ import print_function',
'from __future__ import with_statement',
'from numpy import set_printoptions',
'set_printoptions(suppress=True, precision=4)',
'from sympy import init_printing',
'init_printing(forecolor="White")'],
'pylab': 'auto'},
'StoreMagics': {'autorestore': True},
'ZMQInteractiveShell': {'autocall': 0, 'banner1': ''}}
Run Code Online (Sandbox Code Playgroud)
所以它应该有未来的分裂和numpy抑制,但它实际上没有:
division
Out[1]: _Feature((2, 2, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0), 8192)
4/5
Out[2]: 0
np.get_printoptions()
Out[3]:
{'edgeitems': 3,
'formatter': None,
'infstr': 'inf',
'linewidth': 75, …
Run Code Online (Sandbox Code Playgroud) 换句话说,我想制作一个热图(或曲面图),其颜色随2个变量的变化而变化.(具体来说,亮度=幅度和色调=相位.)有没有本地方法来做到这一点?类似情节的一些例子:
在NumPy函数中,通常有初始行检查变量类型,强制它们是某些类型等.有人可以在scipy.signal.square中解释这些行的要点吗?从自身中减去一个值有什么作用?
t,w = asarray(t), asarray(duty)
w = asarray(w + (t-t))
t = asarray(t + (w-w))
Run Code Online (Sandbox Code Playgroud)