我在NumPy中有两个简单的一维数组.我应该能够使用numpy.concatenate连接它们.但我得到以下代码的错误:
TypeError:只能将length-1数组转换为Python标量
import numpy
a = numpy.array([1, 2, 3])
b = numpy.array([5, 6])
numpy.concatenate(a, b)
Run Code Online (Sandbox Code Playgroud)
为什么?
我在OSX上安装了postgresql.当我运行psql时,我得到了
$ psql
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5433"?
Run Code Online (Sandbox Code Playgroud)
但是,来自/ etc/services
postgresql 5432/udp # PostgreSQL Database
postgresql 5432/tcp # PostgreSQL Database
# Tom Lane <tgl@sss.pgh.pa.us>
pyrrho 5433/tcp # Pyrrho DBMS
pyrrho 5433/udp # Pyrrho DBMS
Run Code Online (Sandbox Code Playgroud)
5433被pyrrho占据,5432被分配给pg.我可以联系
psql -p 5432
Run Code Online (Sandbox Code Playgroud)
但为什么psql认为它是5433,我如何让psql默认在正确的位置?
我试图在R中打印多行消息.例如,
print("File not supplied.\nUsage: ./program F=filename",quote=0)
Run Code Online (Sandbox Code Playgroud)
我得到了输出
File not supplied.\nUsage: ./program F=filename
Run Code Online (Sandbox Code Playgroud)
而不是期望的
File not supplied.
Usage: ./program F=filename
Run Code Online (Sandbox Code Playgroud) 我需要一个SQL语句来检查是否满足一个条件:
SELECT * FROM my_table WHERE my_table.x=1 OR my_table.y=1
Run Code Online (Sandbox Code Playgroud)
我想以'Rails 3'的方式做到这一点.我在寻找类似的东西:
Account.where(:id => 1).or.where(:id => 2)
Run Code Online (Sandbox Code Playgroud)
我知道我总是可以回退到sql或条件字符串.但是,根据我的经验,这在组合范围时经常会导致混乱.做这个的最好方式是什么?
另一个相关的问题是,如何描述依赖于OR条件的关系.我找到的唯一方法:
has_many :my_thing, :class_name => "MyTable", :finder_sql => 'SELECT my_tables.* ' + 'FROM my_tables ' +
'WHERE my_tables.payer_id = #{id} OR my_tables.payee_id = #{id}'
Run Code Online (Sandbox Code Playgroud)
然而,当组合使用时,这些再次破裂.有没有更好的方法来指定这个?
我克隆了一个git repo然后开始在它的主分支中玩.过了一会儿,我想忽略我刚刚做出的改变(不提交它们),然后切换到另一个分支.但是,它阻止我切换,因为有未提交的更改.如何在不隐藏它们的情况下忽略它们?这是发生的事情:
$ git checkout gh-pages
error: Your local changes to the following files would be overwritten by checkout:
somefile.txt
Please, commit your changes or stash them before you can switch branches.
Aborting
Run Code Online (Sandbox Code Playgroud) 我想在tableview中获取单元格的位置.从这个代码我得到单元格位置
int numberOfSections = [UITableView numberOfSections];
int numberOfRows = 0;
NSIndexPath *tempIndexPath = nil;
UITableViewCell *tempCell = nil;
for(int i=0;i<numberOfSections;i++)
{
numberOfRows = [UITableView numberOfRowsInSection:i];
for(int j=0;j<numberOfRows;j++
{
tempIndexPath = [NSIndexPath indexPathForRow:j inSection:i];
tempCell = [UITableView cellForRowAtIndexPath:tempIndexPath];
NSLog("Y postion for cell at (Row = %d,Section = %d) is :%f",tempCell.frame.origin.y);
}
}
Run Code Online (Sandbox Code Playgroud)
它是在tableview中计算单元格的y轴但我的问题是我想在tableview rect的可见区域中获取单元格位置.即如果表视图的大小为cgrectmake(0,0,200,500)且单元格高度为100像素.所以tableview将显示5行.如果我向下滚动并选择第7行.我将得到它的y轴700.但是单元格将在(0,0,200,500)帧内.如何在此框架内获取单元格位置(0,0,200,500).
这有效:
print "Hello World%s" %"!"
Run Code Online (Sandbox Code Playgroud)
但事实并非如此
print "Hello%20World%s" %"!"
Run Code Online (Sandbox Code Playgroud)
错误是 ValueError: unsupported format character 'W' (0x57) at index 8
我使用的是Python 2.7.
我为什么要这样做?好%20用于代替网址中的空格,如果使用它,我不能用printf格式形成字符串.但为什么Python会这样做呢?
可能重复:
如何将函数应用于R中矩阵(或数据帧)的每一行
我想将一个函数应用于数据框中的每一行,但是,R默认将它应用于每一列.我怎么强迫它呢?
> a = as.data.frame(list(c(1,2,3),c(10,0,6)),header=T)
> a
c.1..2..3. c.10..0..6.
1 1 10
2 2 0
3 3 6
> sapply(a,min)
c.1..2..3. c.10..0..6.
1 0
Run Code Online (Sandbox Code Playgroud)
我想要类似的东西
1 2
2 0
3 3
Run Code Online (Sandbox Code Playgroud) 我试图在Rcpp函数中打开一个文件,所以我需要文件名作为char*或std :: string.
到目前为止,我尝试过以下方法:
#include <Rcpp.h>
#include <boost/algorithm/string.hpp>
#include <fstream>
#include <string>
RcppExport SEXP readData(SEXP f1) {
Rcpp::CharacterVector ff(f1);
std::string fname = Rcpp::as(ff);
std::ifstream fi;
fi.open(fname.c_str(),std::ios::in);
std::string line;
fi >> line;
Rcpp::CharacterVector rline = Rcpp::wrap(line);
return rline;
}
Run Code Online (Sandbox Code Playgroud)
但显然,因为我得到编译时错误as不起作用Rcpp::CharacterVector.
foo.cpp: In function 'SEXPREC* readData(SEXPREC*)':
foo.cpp:8: error: no matching function for call to 'as(Rcpp::CharacterVector&)'
make: *** [foo.o] Error 1
Run Code Online (Sandbox Code Playgroud)
有没有一种简单的方法从参数中获取字符串或以某种方式从Rcpp函数参数中打开文件?
我想在R中使用字典/地图数据结构,类似于Python dict或C++ STL std::map或std::hash_map.
我可以做以下所有事情.它们的使用和/或性能有差异吗?如果是这样,哪个是在R中拥有这样一个数据结构的最佳方式?
> mm = c()
> mm["my key"] = 10
> mm[["my key"]]
[1] 10
> mm
my key
10
> mm = list()
> mm["my key"] = 10
> mm[["my key"]]
[1] 10
> mm
$`my key`
[1] 10
> mm = vector()
> mm["my key"] = 10
> mm[["my key"]]
[1] 10
> mm
my key
10
Run Code Online (Sandbox Code Playgroud) r ×4
python ×2
arrays ×1
c++ ×1
dataframe ×1
dictionary ×1
git ×1
git-branch ×1
git-stash ×1
iphone ×1
numpy ×1
port ×1
postgresql ×1
psql ×1
rcpp ×1
ruby ×1
sapply ×1
uitableview ×1