A numpy matrix can be reshaped into a vector using reshape function with parameter -1. But I don't know what -1 means here.
For example:
a = numpy.matrix([[1, 2, 3, 4], [5, 6, 7, 8]])
b = numpy.reshape(a, -1)
Run Code Online (Sandbox Code Playgroud)
The result of b
is: matrix([[1, 2, 3, 4, 5, 6, 7, 8]])
有谁知道-1在这里意味着什么?并且似乎python赋予-1几个含义,例如:array[-1]
表示最后一个元素.你能解释一下吗?
我是OpenCV的新手,我想在Ubuntu 12.04上使用VideoWriter将Mat图像写入视频.但是在构建VideoWriter时,出现了错误.
似乎OpenCV使用默认参数调用ffmpeg API,而ffmpeg使用其默认参数调用x264.然后这些设置被破解为libx264.因此"无法打开编解码器'libx264'"错误.
有人有想法解决这个问题吗?
进一步来说:
错误:
1. Uising CV_FOURCC('H', '2', '6', '4')
[libx264 @ 0x255de40] broken ffmpeg default settings detected
[libx264 @ 0x255de40] use an encoding preset (e.g. -vpre medium)
[libx264 @ 0x255de40] preset usage: -vpre <speed> -vpre <profile>
[libx264 @ 0x255de40] speed presets are listed in x264 --help
[libx264 @ 0x255de40] profile is optional; x264 defaults to high
Could not open codec 'libx264': Unspecified error
2. Using FOURCC = -1 to invoke user customized …
Run Code Online (Sandbox Code Playgroud) 我已经在mac上安装了Numpy和Scipy以及virtualenv.
今天,我想在virtualenv下安装Opencv.我尝试:
pip install pyopencv
Run Code Online (Sandbox Code Playgroud)
终端返回:
找不到满足pyopencv要求的版本(版本:2.0.wr1.0.1-demo,2.0.wr1.0.1,2.0.wr1.1.0,2.1.0.wr1.0.0,2.1.0.wr1.0.1, 2.1.0.wr1.0.2,2.1.0.wr1.1.0,2.1.0.wr1.2.0,2.1.0.wr1.2.0-demo,2.1.0.wr1.2.0)清理......没有匹配的发行版pyopencv的版本
我想用python生成一个矩形脉冲。我相信它可以用 numpy 或 scipy 来完成。但我无法从 API 获取它。生成矩形脉冲后,我将使用 matplotlib 绘制它。
我遇到了以下语法来创建一个 python 数组。这对我来说很奇怪。
谁能给我解释一下?我应该如何学习这种语法?
[str(index) for index in range(100)]
Run Code Online (Sandbox Code Playgroud) 我试图将一个代码从 python 移植到 matlab,但我遇到了 numpy fft2 和 matlab fft2 之间的一个不一致:
peak =
4.377491037053e-223 3.029446976068e-216 ...
1.271610790463e-209 3.237410810582e-203 ...
Run Code Online (Sandbox Code Playgroud)
(大数据不能直接罗列,可以在这里访问:https : //drive.google.com/file/d/0Bz1-hopez9CGTFdzU0t3RDAyaHc/edit?usp=sharing)
MATLAB:
fft2(peak) --(sample result)
12.5663706143590 -12.4458341615690
-12.4458341615690 12.3264538927637
Run Code Online (Sandbox Code Playgroud)
Python:
np.fft.fft2(peak) --(sample result)
12.56637061 +0.00000000e+00j -12.44583416 +3.42948517e-15j
-12.44583416 +3.35525358e-15j 12.32645389 -6.78073635e-15j
Run Code Online (Sandbox Code Playgroud)
请帮我解释原因,并就如何解决它提出建议。
python ×5
numpy ×3
opencv ×2
ffmpeg ×1
h.264 ×1
libx264 ×1
macos ×1
matlab ×1
matplotlib ×1
scipy ×1
ubuntu-12.04 ×1
virtualenv ×1