我目前正在练习matplotlib.这是我练习的第一个例子.
#!/usr/bin/python
import matplotlib.pyplot as plt
radius = [1.0, 2.0, 3.0, 4.0]
area = [3.14159, 12.56636, 28.27431, 50.26544]
plt.plot(radius, area)
plt.show()
Run Code Online (Sandbox Code Playgroud)
当我运行此脚本时python ./plot_test.py,它会正确显示绘图.但是,我自己运行它./plot_test.py,它抛出以下内容:
Traceback (most recent call last):
File "./plot_test.py", line 3, in <module>
import matplotlib.pyplot as plt
ImportError: No module named matplotlib.pyplot
Run Code Online (Sandbox Code Playgroud)
python是否在不同的位置寻找matplotlib?
环境是:
Mac OS X 10.8.4 64bit
built-in python 2.7
Run Code Online (Sandbox Code Playgroud)
numpy,scipy,matplotlib安装有:
sudo port install py27-numpy py27-scipy py27-matplotlib \
py27-ipython +notebook py27-pandas py27-sympy py27-nose
Run Code Online (Sandbox Code Playgroud) 我正在尝试为Python找到或开发Integer Partitioning代码.
FYI,整数分区将给定的整数n表示为小于n的整数之和.例如,整数5可以表示为4 + 1 = 3 + 2 = 3 + 1 + 1 = 2 + 2 + 1 = 2 + 1 + 1 + 1 = 1 + 1 + 1 + 1 + 1
我找到了很多解决方案.http://homepages.ed.ac.uk/jkellehe/partitions.php和http://code.activestate.com/recipes/218332-generator-for-integer-partitions/
但是,我真正想要的是限制分区数量.
比如说,#分区k = 2,一个程序只需要显示5 = 4 + 1 = 3 + 2,
如果k = 3,5 = 3 + 1 + 1 = 2 + 2 + 1
a = [1, 2, 3, 4, 5, 6]
# OR !
a = ['one', 'two', 'three', 'four', 'five', 'six']
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我只想知道所有可能的组合; 选择ķ间元件一个.如果我使用b = scipy.misc.comb(a, 1),它显示:
b = [1, 2, 3, 4, 5, 6]
Run Code Online (Sandbox Code Playgroud)
其中b i只是我选择1.如果a是一个字符串数组,它就不起作用.
我真正想要的是:
b = [[1], [2], [3], [4], [5], [6]]
# OR !
b = [['one'], ['two'], ['three'], ['four'], ['five'], ['six']]
Run Code Online (Sandbox Code Playgroud)
这意味着,数组a中元素中可能的1个选定元素的集合
如果我使用MATLAB,这很容易.但我正在尝试使用SciPy堆栈.
当我构建源代码时,它会抛出一个错误: declaration of 'globalMemTrace' has a different language linkage
#ifdef MEMDEBUG_SIMULATIONS
#include "mem-trace.h"
MemTrace *globalMemTrace;
#endif
// omitted unrelated parts
int Tcl_AppInit(Tcl_Interp *interp)
{
#ifdef MEMDEBUG_SIMULATIONS
extern MemTrace *globalMemTrace;
globalMemTrace = new MemTrace;
#endif
}
Run Code Online (Sandbox Code Playgroud)
我已经用Google搜索过几次了.有人说,这是由于一个错误,如果clang和一些说使用extern不同的技巧可以解决它.
但由于我不是这样的专业,我已经尝试了其中的一些而未能解决它.有什么好方法可以解决它吗?
它是用C++编写的,问题发生在 extern MemTrace *globalMemTrace;
在中mdart/mdart_function.h,hash定义了功能。
inline nsaddr_t hash(nsaddr_t id) {
bitset<ADDR_SIZE> tempAddress_ (id);
bitset<ADDR_SIZE> address_;
for(unsigned int i=0; i<ADDR_SIZE; i++) {
if (tempAddress_.test(i)) {
address_.set(ADDR_SIZE - 1 - i);
}
}
address_.flip(ADDR_SIZE - 1);
nsaddr_t temp = (nsaddr_t) address_.to_ulong();
#ifdef DEBUG
fprintf(stdout, "\thash = %s\n", bitString(temp));
#endif
return temp;
}
Run Code Online (Sandbox Code Playgroud)
在另一个源文件中,hash使用正确的头文件引用该函数,包括:
nsaddr_t dstAdd_ = hash(reqId);
Run Code Online (Sandbox Code Playgroud)
但是,还有另一个hash,std::hash它抛出error: reference to 'hash' is ambiguous在我构建它时。
有什么方法可以指定hash尝试使用哪些源代码?我知道std::hash,但是hash在头文件中呢?
python ×3
c++ ×2
algorithm ×1
ambiguous ×1
c ×1
combinations ×1
hash ×1
matplotlib ×1
numpy ×1
scipy ×1