我想将具有形状的灰度图像转换为具有形状(height,width)的3通道图像(height,width,nchannels).工作是用a完成的for-loop,但必须有一个简洁的方法.这是程序中的一个代码,有人可以给出一个提示.请指教.
30 if img.shape == (height,width): # if img is grayscale, expand
31 print "convert 1-channel image to ", nchannels, " image."
32 new_img = np.zeros((height,width,nchannels))
33 for ch in range(nchannels):
34 for xx in range(height):
35 for yy in range(width):
36 new_img[xx,yy,ch] = img[xx,yy]
37 img = new_img
Run Code Online (Sandbox Code Playgroud) 
我只更改搜索路径以通知Xcode opencv所在的位置.这是我的搜索路径:
Framework search path: /usr/local/lib
Library search path: /usr/local/Cellar/opencv/2.4.11/lib
/usr/local/Cellar/opencv/2.4.11_1/lib
/user/local/lib
Header search path: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/usr/local/include
Run Code Online (Sandbox Code Playgroud)
错误:
In file included from /Users/lilisun/Documents/opencv_projects/faceExtractor/faceExtractor/main.cpp:8:
In file included from /usr/local/include/opencv2/objdetect/objdetect.hpp:46:
In file included from /usr/local/include/opencv2/core/core.hpp:49:
In file included from /usr/local/include/opencv2/core/types_c.h:55:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/assert.h:44:
In file included from /usr/local/include/c++/5.1.0/tr1/stdlib.h:32:
In file included from /usr/local/include/c++/5.1.0/tr1/cstdlib:34:
/usr/local/include/c++/5.1.0/cstdlib:118:11: error: no member named 'div_t' in the global namespace
using ::div_t;
~~^
/usr/local/include/c++/5.1.0/cstdlib:119:11: error: no member named 'ldiv_t' in the global namespace
using ::ldiv_t;
~~^
/usr/local/include/c++/5.1.0/cstdlib:121:11: …Run Code Online (Sandbox Code Playgroud) 我有两个向量a = c(1,2,3),b = c(1,2,3)
我想测试是否a完全相同b.我知道结果可以给出sum(a == b) == length(a),但有没有优雅的方式?
我将图像放在一个numpy数组中,并使用以下代码绘制它。我如何告诉程序不要绘制轴,例如(0, 100, 200...)
import matplotlib.pyplot as plt
plt.figure()
plt.imshow(output_ndarray)
plt.savefig(output_png)
Run Code Online (Sandbox Code Playgroud)
我正在使用spark并使用HiveContext执行HQL查询.我想table(student)从database(test)蜂巢中删除.那么,这个命令delete test.student会运行吗hivecontext?它可以在teradata中运行,因此我可以在Hive中使用它(在火花中).