我正在尝试从文档https://docs.python.org/2.7/extending/embedding.html编译示例,我的代码看起来与5.1下的代码完全相同:
#include <Python.h>
int
main(int argc, char *argv[])
{
Py_SetProgramName(argv[0]);
Py_Initialize();
PyRun_SimpleString("from time import time, ctime\n"
"print 'Today is', ctime(time())\n");
Py_Finalize();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我使用以下命令编译它,它对我来说很好,并给我所需的目标文件:
gcc -c $(python2.7-config --cflags) embedpy.c
Run Code Online (Sandbox Code Playgroud)
要链接它,我使用以下命令,最终出现以下错误:
gcc $(/usr/bin/python2.7-config --ldflags) embedpy.o
embedpy.o: In function `main':
/home/miguellissimo/embedpy.c:6: undefined reference to `Py_SetProgramName'
/home/miguellissimo/embedpy.c:7: undefined reference to `Py_Initialize'
/home/miguellissimo/embedpy.c:8: undefined reference to `PyRun_SimpleStringFlags'
/home/miguellissimo/embedpy.c:11: undefined reference to `Py_Finalize'
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
我无法找出我做错了什么,或者我忘了让这个例子工作.
PS:python2.7-config命令在我的Xubuntu机器上提供以下输出:
>>> python2.7-config --cflags
-I/usr/include/python2.7 -I/usr/include/x86_64-linux-gnu/python2.7 -fno-stri
ct-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector …
Run Code Online (Sandbox Code Playgroud) 我对tensorflow相对较新,并希望使用tf.contrib.learn中的DNNRegressor进行回归任务.但是,我想要有几个(例如十个),而不是一个输出节点.
如何配置我的回归器以调整许多输出节点以满足我的需求?
我的问题与已经在SO上提出的以下问题有关,但似乎没有可行的答案(我使用的是TensorFlow版本0.11)
我使用 matplotlib 库在 python 中绘制数据。在我的图中,我也有一些文字来区分数据。问题是文本越过图形窗口中的边框。是否可以使绘图的边框在相应位置切断文本,并且仅当我在绘图内平移时,其余文本才可见(但仅当在绘图区域内时)。我使用 text() 函数来显示文本
[编辑:]
代码如下所示:
fig = plt.figure()
ax = fig.add_subplot(111)
# ...
txt = ax.text(x, y, n, fontsize=10)
txt.set_clip_on(False) # I added this due to the answer from tcaswell
Run Code Online (Sandbox Code Playgroud)