当我尝试使用pyplot时matplotlib:
import matplotlib
print matplotlib.pyplot # just checking
Run Code Online (Sandbox Code Playgroud)
它给了我 AttributeError: 'module' object has no attribute 'pyplot'
它可以通过以下方式解决:
import matplotlib.pyplot
Run Code Online (Sandbox Code Playgroud)
但我真的很困惑的是,
import numpy
print numpy.random
Run Code Online (Sandbox Code Playgroud)
给我 <module 'numpy.random' from '/Applications/Canopy.app/appdata/canopy-1.0.3.1262.macosx-x86_64/Canopy.app/Contents/lib/python2.7/site-packages/numpy/random/__init__.pyc'>
两种情况有什么区别?pyplot在第一个例子中不能被调用,但是random在第二个例子中.我认为它与某种包和模块有关.但我不是蟒蛇的专业人士,因此要求回答.
我想在地图上画一些箭头。通过一些谷歌搜索,我了解到annotation_customwithrasterGrob可以做到这一点:
library(ggplot2)
library(png)
library(grid)
img = readPNG('floorplan.png')
g = rasterGrob(img, interpolate = TRUE)
data = read.csv('est_err_structured.csv', header = FALSE)
x1 = data$V1
y1 = data$V2
x2 = data$V3
y2 = data$V4
p = ggplot() +
geom_segment(data = data, mapping = aes(x = x1, y = y1, xend = x2, yend = y2),
arrow = arrow(length = unit(0.2, 'cm'))) +
annotation_custom(g, xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf) +
xlab('x (m)') …Run Code Online (Sandbox Code Playgroud) 例如,我有一个字符串列表:
str_list =['one', 'two', 'three', 'four', 'five']
Run Code Online (Sandbox Code Playgroud)
我想在屏幕上打印所有这些:
for c in str_list:
print c
print ', ' # word separator
Run Code Online (Sandbox Code Playgroud)
这导致:
one, two, three, four, five,
Run Code Online (Sandbox Code Playgroud)
这里,行末不需要逗号,我不想打印它.如何修改上面的代码而不是打印最后一个逗号?
它可以通过以下方式解决enumerate:
for idx, c in enumerate(str_list):
print c
if idx < len(str_list) - 1:
print ','
Run Code Online (Sandbox Code Playgroud)
但是,我认为可能有更优雅的方式来处理这个问题.
编辑:也许我以为我举了一个太简单的例子.假设我应该为每个迭代调用函数x(),除了最后一个迭代:
for idx, x in enumerate(list_x):
if idx < len(list_x) - 1:
something_right(x)
else:
something_wrong(x)
Run Code Online (Sandbox Code Playgroud) 我正在尝试编译此处编写的源代码,这会触发用户空间中的Wi-Fi主动扫描.
它需要netlink库,所以我做到了 sudo apt-get install libnl-3-dev libnl-genl-3-dev
并编译它gcc $(pkg-config --cflags --libs libnl-3.0 libnl-genl-3.0) scan_access_points.c,这是相同的gcc -I/usr/include/libnl3 -lnl-genl-3 -lnl-3 scan_access_points.c
但编译失败了数量undefined reference to 'SOMETHING'.日志在下面,你可以在这里看到它.
/tmp/ccTQB59P.o: In function `family_handler':
scan_access_points.c:(.text+0xc8): undefined reference to `nlmsg_hdr'
scan_access_points.c:(.text+0xd0): undefined reference to `nlmsg_data'
scan_access_points.c:(.text+0xe5): undefined reference to `genlmsg_attrlen'
scan_access_points.c:(.text+0xf8): undefined reference to `genlmsg_attrdata'
scan_access_points.c:(.text+0x114): undefined reference to `nla_parse'
scan_access_points.c:(.text+0x133): undefined reference to `nla_data'
scan_access_points.c:(.text+0x146): undefined reference to `nla_len'
scan_access_points.c:(.text+0x160): undefined reference to `nla_len'
scan_access_points.c:(.text+0x171): undefined reference to `nla_data' …Run Code Online (Sandbox Code Playgroud) 简而言之,请考虑下面的(伪)代码:
switch (n) {
case 15:
(keyword) customtemplate<15> t_var; /* I want it to be outside of switch */
break;
case 255:
(keyword) customtemplate<255> t_var; /* I want it to be outside of switch */
break;
default:
break;
}
t_var.do_something();
Run Code Online (Sandbox Code Playgroud)
我想知道是否有一些(keyword)使得跟随变量是全局的,或者在switch-case范围之外.
我想要这样一个奇怪的代码的原因是,我不能声明具有任意数量的n的模板变量,即:
int n = 15; // or int n = 255;
custometemplate<n> t_var; /* I can't do this */
t_var.do_something;
Run Code Online (Sandbox Code Playgroud)
在customtemplate这个帖子中提到的是实际上可以RS<n,k>在ezpwd -里德-所罗门.我要声明RS<n, k>这是一个RS<15,2>, RS<15, 4>, RS<15, …
我在hostap中找到了一些代码.以下是简化的:
a.h// it just declares 'there is a struct a'
struct a;
// it seems like an accessor to a private member b
int get_b(struct a);
Run Code Online (Sandbox Code Playgroud)
a.c// definition is seprated from a header file
struct a {
int b;
};
int get_b(struct a) {
return a.b;
}
Run Code Online (Sandbox Code Playgroud)
a.o使用这两个文件生成目标文件.
如果其他源代码想要使用struct a,则无法直接访问成员b,并且编译器会抱怨dereferencing incomplete type.我只能访问一个成员b有get_b().
第一次,我对这种模式感到非常沮丧.但最后,我觉得如果有人想要保护其完整性,这是一个设计良好的模式struct a(例如,成员的价值观必须按照某些标准设定,或者成员彼此依赖,以便一个成员的变化会影响其他)
这种模式有术语吗?
我正在 GNU Radio 中构建某个模块。(我们称之为我的模块。)
GNU Radio 用于cmake构建和安装一个 my-module。
在项目中,我需要使用一个别人制作的模块。这可以是it++和其他 gnuradio 模块。我将使用 gnuradio 模块。(让我们称之为other-module。)
要在我的 gr 模块中使用其他模块,我需要使用find_package,pkg_check_modules并find_library告诉“我将使用预先构建的模块”
并且pkg_check_modules(PC_ITPP itpp)可以成功检测到它++。
但我很难找到other-module. 正如我所说pkg_check_modules(PC_OTHER_MODULE other_module),它无法检测到模块。
我很好奇的是,moduleinpkg_check_modules(<PREFIX> <MODULE>)代表什么以及 cmake 如何以及在哪里找到给定模块?
当然,我认为它不是内核模块,因为我在内核模块列表中没有看到它++。那么,它们是 cmake 模块吗?我也不这么认为,因为cmake --help-module-list没有显示它++。
是否有一个特殊文件包含可以被 cmake 引用的模块列表?那么,是否应该it++在构建和安装步骤中在该文件中注册模块和其他库,以便 cmake 将其识别为模块?