我正在寻找一种方法来使用我的DataFrame中的舍入数值来在Pandas条形图中注释我的条形图.
>>> df=pd.DataFrame({'A':np.random.rand(2),'B':np.random.rand(2)},index=['value1','value2'] )
>>> df
A B
value1 0.440922 0.911800
value2 0.588242 0.797366
Run Code Online (Sandbox Code Playgroud)
我想得到这样的东西:

我尝试使用此代码示例,但注释都集中在x刻度上:
>>> ax = df.plot(kind='bar')
>>> for idx, label in enumerate(list(df.index)):
for acc in df.columns:
value = np.round(df.ix[idx][acc],decimals=2)
ax.annotate(value,
(idx, value),
xytext=(0, 15),
textcoords='offset points')
Run Code Online (Sandbox Code Playgroud) 我想知道是否可以将在编译行上带参数的宏传递给gcc或其他C/C++编译器.
我以前从未见过这个,但它实际上对于我一直在做的一些OpenCL开发很有用,我想用一个可以在编译时替换的宏来替换一个函数名.
以下是一个例子:
int y, x = 0;
y = HASH(x);
Run Code Online (Sandbox Code Playgroud)
如果可以在编译行上将HASH定义为宏,那将是很好的,所以当我编译程序时,我可以根据需要重新定义HASH.例如,如果我能这样做会很棒gcc -DHASH(X)=(hash_fcn1(X)) program.c -o program,但我以前从未见过这种事.
我用clBuildProgram尝试过但没有运气.
我意识到我可以让另一个程序通过程序并将正确的函数名替换为HASH,但我想知道是否有一种简单的方法可以在不使用sed,awk或字符串替换等工具的情况下执行此操作或者用我选择的语言编写正则表达式库.
另一个解决方案是在命令行上定义一个平面宏,然后在实际源文件中有一系列保护,控制如何在源文件中定义宏,例如在这个其他帖子中如何比较C中的字符串条件预处理程序指令.
我有一个关于滥用C预处理器的问题,这个特定的例子与Linux系统上的gcc有关(如果这有所不同).
我想做类似以下的事情:
char filename[] = "hello.txt";
convert_and_include(filename);
Run Code Online (Sandbox Code Playgroud)
其中convert_and_include将.txt的最后三个字符更改为.h,然后将hello.h作为头文件包含在内.我知道这听起来很奇怪,但我保证你有充分的理由想要这样做.
inline void convert_and_include(char filename[]) __attribute__((always_inline))
inline void convert_and_include(char filename[]){
// Error checking has been removed for clarity.
filename[6] = 'h';
filename[7] = '\0';
filename[8] = '\0';
#include AS_STRING(filename) // AS_STRING should evaluate to "hello.h"
}
Run Code Online (Sandbox Code Playgroud) 有没有一种简单的方法可以使左移和减法像在 C 中那样使用 Cython 对无符号整数进行操作?
例如:
def left_shift(unsigned int x, unsigned int shift):
return x << shift
def main():
print left_shift(0xffffffff, 4)
print left_shift(0xffffffff, 8)
print left_shift(0xffffffff, 12)
Run Code Online (Sandbox Code Playgroud)
我希望这能打印十进制等价物
0xfffffff0
0xffffff00
0xfffff000
Run Code Online (Sandbox Code Playgroud)
这实际上就是我得到的。
4294967280
4294967040
4294963200
Run Code Online (Sandbox Code Playgroud)
然而,如果我尝试做一些更复杂的事情,例如在大输入上使用 Jenkins 的哈希函数之一,这就是我得到的:
def hash_fcn1(unsigned int key):
key = (key ^ 0xdeadbeef) + (key << 4)
key = key ^ (key >> 10)
key = key + (key << 7)
key = key ^ (key >> 13)
return key
hash_fcn1(0xffffffff)
File "./hash_fcn_test.py", line 94, …Run Code Online (Sandbox Code Playgroud)