有没有办法抑制pytest的内部弃用警告?
语境:我期待评估从移植测试套件的难度nose来pytest.该套件相当大,并且基于使用nose风格yield的测试生成器.
我想首先确保现有测试通过pytest,然后可能将测试生成器更改为parameterized.
刚运行$ pytest path-to-test-folderpytest 3.0.4完全由页面和页面控制
WC1 ~repos/numpy/numpy/lib/tests/test_twodim_base.py yield tests are deprecated, and scheduled to be removed in pytest 4.0
Run Code Online (Sandbox Code Playgroud)
有没有办法解决这些警告?
我要重新安装numpy,并scipy在我的Ubuntu清醒.由于这些东西带有很多依赖项,我想知道是否有一个全面的测试套件来检查新安装是否真的有效.
当然,我可以拿一堆我的脚本并逐个运行它们以确定它们是否继续工作,但这无法防止在将来的某个时候我会尝试使用我没有做过的事情.以前使用它会破坏(或者更糟糕的是,默默地产生不存在).
好的,成员变量可用于初始化初始化列表中的其他成员变量(注意初始化顺序等).会员职能怎么样?具体来说,这个片段是否符合C++标准?
struct foo{
foo(const size_t N) : N_(N), arr_(fill_arr(N)) {
//arr_ = fill_arr(N); // or should I fall back to this one?
}
std::vector<double> fill_arr(const size_t N){
std::vector<double> arr(N);
// fill in the vector somehow
return arr;
}
size_t N_;
std::vector<double> arr_;
// other stuff
};
Run Code Online (Sandbox Code Playgroud) np.sum和之间有什么区别np.add.reduce?
虽然文档很明确:
例如,add.reduce()等效于sum().
两者的性能似乎完全不同:相对较小的阵列大小add.reduce大约快两倍.
$ python -mtimeit -s"import numpy as np; a = np.random.rand(100); summ=np.sum" "summ(a)"
100000 loops, best of 3: 2.11 usec per loop
$ python -mtimeit -s"import numpy as np; a = np.random.rand(100); summ=np.add.reduce" "summ(a)"
1000000 loops, best of 3: 0.81 usec per loop
$ python -mtimeit -s"import numpy as np; a = np.random.rand(1000); summ=np.sum" "summ(a)"
100000 loops, best of 3: 2.78 usec per loop
$ python -mtimeit -s"import numpy as …Run Code Online (Sandbox Code Playgroud) 在matplotlib中,有一种简单的方法可以在不中断脚本控制流的情况下绘制图形吗?
为了清晰起见使用伪代码,这是我想要实现的:
fig1 = figure()
fig1.plot_a_figure(datasets)
for dataset in datasets:
results = analyze(dataset) # this takes several minutes
update(fig1)
pop_up_another_figure(results) # would like to have a look at this one
# while the next dataset is being processed
Run Code Online (Sandbox Code Playgroud)
当然,我可以保存这些中间数字,但我只需要快速浏览一下它们,最好让它们实时弹出屏幕.
编辑:一个可运行的例子:
#!/usr/bin/python
import pylab as plb
import matplotlib.pyplot as plt
fig1=plt.figure(1)
ax = fig1.add_subplot(1,1,1)
ax.plot([1,2,3],[4,5,6],'ro-')
#fig1.show() # this does not show a figure if uncommented
plt.show() # until the plot window is closed, the next line is not executed
print "doing …Run Code Online (Sandbox Code Playgroud) 在尝试优化代码时,我对由kcachegrdind和生成的配置文件的差异感到有些困惑gprof.具体来说,如果我使用gprof(使用-pg交换机编译等),我有这个:
Flat profile:
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls ms/call ms/call name
89.62 3.71 3.71 204626 0.02 0.02 objR<true>::R_impl(std::vector<coords_t, std::allocator<coords_t> > const&, std::vector<unsigned long, std::allocator<unsigned long> > const&) const
5.56 3.94 0.23 18018180 0.00 0.00 W2(coords_t const&, coords_t const&)
3.87 4.10 0.16 200202 0.00 0.00 build_matrix(std::vector<coords_t, std::allocator<coords_t> > const&)
0.24 4.11 0.01 400406 0.00 0.00 std::vector<double, std::allocator<double> >::vector(std::vector<double, std::allocator<double> > const&)
0.24 4.12 0.01 100000 …Run Code Online (Sandbox Code Playgroud) 我正在尝试在XML文件中对一堆记录进行排序.诀窍是我需要为不同的节点使用不同的元素进行排序.举一个最简单的例子,我想这样做:给定一个xml文件
<?xml version="1.0" encoding="utf-8" ?>
<buddies>
<person>
<nick>Jim</nick>
<last>Zulkin</last>
</person>
<person>
<first>Joe</first>
<last>Bumpkin</last>
</person>
<person>
<nick>Pumpkin</nick>
</person>
<person>
<nick>Andy</nick>
</person>
</buddies>
Run Code Online (Sandbox Code Playgroud)
我想把它转换成
Andy
Joe Bumpkin
Pumpkin
Jim Zulkin
Run Code Online (Sandbox Code Playgroud)
也就是说,可以通过名字,姓氏和缺口的任何子集列出人.排序键是姓氏,如果它存在,否则它是昵称,如果它存在,否则是名字.
我在这里遇到困难,因为使用变量作为xsl:显然不允许使用排序键.
我目前最好的镜头是进行两步转换:使用此样式表为每条记录添加一个特殊标记
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="no" indent="yes"/>
<!-- *** convert each person record into a person2 record w/ the sorting key *** -->
<xsl:template match="/buddies">
<buddies>
<xsl:for-each select="person">
<person2>
<xsl:copy-of select="*"/>
<!-- add the sort-by tag -->
<sort-by>
<xsl:choose>
<xsl:when test="last"> <xsl:value-of select="last"/>
</xsl:when>
<xsl:otherwise> …Run Code Online (Sandbox Code Playgroud) 在matplotlib中,将文本框大小转换为数据坐标的方法是什么?例如,在这个玩具脚本中,我正在微调文本框的坐标,使其位于数据点的旁边.
#!/usr/bin/python
import matplotlib.pyplot as plt
xx=[1,2,3]
yy=[2,3,4]
dy=[0.1,0.2,0.05]
fig=plt.figure()
ax=fig.add_subplot(111)
ax.errorbar(xx,yy,dy,fmt='ro-',ms=6,elinewidth=4)
# HERE: can one get the text bbox size?
txt=ax.text(xx[1]-0.1,yy[1]-0.4,r'$S=0$',fontsize=16)
ax.set_xlim([0.,3.4])
ax.set_ylim([0.,4.4])
plt.show()
Run Code Online (Sandbox Code Playgroud)
有没有办法做这样的伪代码呢?
x = xx[1] - text_height
y = yy[1] - text_width/2
ax.text(x,y,text)
Run Code Online (Sandbox Code Playgroud) 我有一个单人单文件夹mercurial存储库.目录结构很简单:
P104
lecture_notes
files under version control live here
Run Code Online (Sandbox Code Playgroud)
过了一会儿,我意识到我想在存储库中有两个目录,就像这样
P104
lecture_notes
files under version control live here (.hg is here)
homework
more files under version control
Run Code Online (Sandbox Code Playgroud)
现在,如果我只是尝试将文件添加到存储库,它将失败:
br@ymir:~/P104/lecture_notes$ ll ..
total 16
drwxr-xr-x 4 br br 4096 2012-02-02 18:05 ./
drwxr-xr-x 4 br br 4096 2012-02-01 20:46 ../
drwxr-xr-x 2 br br 4096 2012-02-02 17:44 homework/
drwxr-xr-x 4 br br 4096 2012-02-02 18:06 lecture_notes/
br@ymir:~/P104/lecture_notes$ hg add ../homework/hw1_P104.tex
abort: ../homework/hw1_P104.tex not under root
Run Code Online (Sandbox Code Playgroud)
我的第一个想法是在目录结构中将repo克隆一级,将文件添加到克隆,并删除原始repo.但即使是克隆也失败了:
br@ymir:~/P104/2011/lecture_notes$ hg clone . .. …Run Code Online (Sandbox Code Playgroud) 我有两个配对值的向量
size(X)=1e4 x 1; size(Y)=1e4 x 1
Run Code Online (Sandbox Code Playgroud)
是否有可能contour plot通过最高密度的点来绘制某种轮廓?即最高聚类=红色,然后在其他地方渐变颜色?
如果您需要更多说明,请询问.问候,
示例数据:
X=[53 58 62 56 72 63 65 57 52 56 52 70 54 54 59 58 71 66 55 56];
Y=[40 33 35 37 33 36 32 36 35 33 41 35 37 31 40 41 34 33 34 37 ];
scatter(X,Y,'ro');
Run Code Online (Sandbox Code Playgroud)

谢谢大家的帮助.还记得我们可以使用hist3:
x={0:0.38/4:0.38}; % # How many bins in x direction
y={0:0.65/7:0.65}; % # How many bins in y direction
ncount=hist3([X Y],'Edges',[x y]);
pcolor(ncount./sum(sum(ncount))); …Run Code Online (Sandbox Code Playgroud) 给定numpy数组的原始二进制表示,明确还原数组所需的完整元数据集是什么?
例如,
>>> np.fromstring( np.array([42]).tostring())
array([ 2.07507571e-322])
Run Code Online (Sandbox Code Playgroud)
这是可以预料的(事后看来,至少):这里我没有告诉fromstring你期望整数,所以它与默认的浮点数一致.
但在我看来,仅指定dtype=np.float64或类似可能或不足够.例如,
>>> a = np.array([42.])
>>> a.dtype
dtype('float64')
>>> a.dtype.byteorder
'='
Run Code Online (Sandbox Code Playgroud)
它的文档告诉我的意思是"原生秩序".意思是,它会在big-endian和little-endian机器上被不同地解释 - 或者我错过了一些简单的东西?
确定嵌套到其他对象的私有部分中的对象的访问权限的确切规则是什么?
例如,在下面剪切的代码中,proxy_tstruct嵌套在该的私有部分中abc_t,但其方法可供该main函数使用.它为什么要编译?
#include <iostream>
#include <valarray>
using namespace std;
class abc_t{
private:
struct proxy_t{
proxy_t operator()(double& a, double& b){ __a=a; __b=b; return *this; }
double a(){ return __a; }
double b(){ return __b; }
private:
double __a, __b;
};
public:
abc_t( const size_t N ){
_a.resize(N,-101.);
_b.resize(N,-202.);
}
double a(size_t j){ return _a[j]; }
double b(size_t j){ return _b[j]; }
proxy_t operator[](const size_t j) { return _proxy(_a[j],_b[j]); }
private:
valarray<double> _a;
valarray<double> _b;
proxy_t …Run Code Online (Sandbox Code Playgroud) 我多次读过使用type*N符号(real*8复杂*16等)可能导致可移植性问题.这里有没有人遇到过这些问题,然后用kinds 解决了?