我正在按照本教程制作相机应用程序,但是教程是在Swift中,我正在使用Xcode 7 beta和Swift2.
http://jamesonquave.com/blog/taking-control-of-the-iphone-camera-in-ios-8-with-swift-part-1/
我听说Swift2现在有一个不同的错误处理方法,所以我想这部分代码需要改变.但我不确定如何.谁能帮我这个?谢谢!
var err : NSError? = nil
captureSession.addInput(AVCaptureDeviceInput(device: captureDevice, error: &err))
if err != nil {
println("error: \(err?.localizedDescription)")
}
Run Code Online (Sandbox Code Playgroud) 我试图在aws ec2实例上运行一个小的python代码(需要pytz和其他一些软件包).当我尝试安装pytz时,我遇到了一些错误:
[ec2-user@ip-172-31-28-178 ~]$ pip install pytz
Collecting pytz
Using cached pytz-2016.7-py2.py3-none-any.whl
Installing collected packages: pytz
Exception:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/usr/local/lib/python2.7/site-packages/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/usr/local/lib/python2.7/site-packages/pip/req/req_set.py", line 784, in install
**kwargs
File "/usr/local/lib/python2.7/site-packages/pip/req/req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/usr/local/lib/python2.7/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "/usr/local/lib/python2.7/site-packages/pip/wheel.py", line 345, in move_wheel_files
clobber(source, lib_dir, True)
File "/usr/local/lib/python2.7/site-packages/pip/wheel.py", line 316, in clobber
ensure_dir(destdir)
File "/usr/local/lib/python2.7/site-packages/pip/utils/__init__.py", …Run Code Online (Sandbox Code Playgroud) 我正在运行python代码来进行某些Web抓取,这意味着该代码有时会将数据写入(附加)到文本文件中。有时代码只会冻结,但Shell中不会显示任何错误消息。我想知道这是否更有可能是因为raspbian系统不可靠,还是因为我的代码存在一些隐藏问题。
在终端我发现了一些像这样的错误:
I tensorflow/core/common_runtime/bfc_allocator.cc:702] Stats:
Limit: 11332668621
InUse: 11332668416
MaxInUse: 11332668416
NumAllocs: 13
MaxAllocSize: 11332445440
Run Code Online (Sandbox Code Playgroud)
但是p2.xlarge实例应该有61GiB内存......这里有什么问题?请帮忙!
我写了一个简单的递归函数来删除具有最大总和的列,直到数据帧减少到我想要的大小.这是代码:
s = pd.DataFrame({'a': [1,1,1,1,1,1],
'b': [2,2,2,2,2,2],
'c': [3,3,3,3,3,3],
'd': [4,4,4,4,4,4],
'e': [5,5,5,5,5,5]})
def recSelect(inputdf):
if inputdf.shape[1]<=2:
return inputdf
else:
total = inputdf.sum()
idx = total.idxmax()
inputdf.drop(idx, axis=1, inplace=True)
return recSelect(inputdf)
recSelect(s)
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,首先删除列'e',然后删除列'd',然后删除'c'.我的问题是:我如何正确地返回'idx'并获得一个列表为['e','d','c']?
这是我尝试过的但它不起作用:
idxs = [] # create an empty list
def recSelect(inputdf):
if inputdf.shape[1]<=2:
return inputdf
else:
total = inputdf.sum()
idx = total.idxmax()
idxs.append(idx) # append each idx
inputdf.drop(idx, axis=1, inplace=True)
return recSelect(inputdf), idxs
Run Code Online (Sandbox Code Playgroud) 我有一个与此主题非常相似的问题,但我想重复使用StandardScaler而不是LabelEncoder.这就是我所做的:
# in one program
dict = {"mean": scaler.mean_, "var": scaler.var_}
# and save the dict
# in another program
# load the dict first
new_scaler = StandardScaler()
new_scaler.mean_ = dict['mean'] # Hoever it doesn't work
new_scaler.var_ = dict['var'] # Doesn't work either...
Run Code Online (Sandbox Code Playgroud)
我也试过set_params,但它只能改变这些参数:copy,with_mean,和with_std.
那么,我怎样才能重新使用我在程序1中得到的缩放器?谢谢!
我正在解析从iOS Health App导出的xml文件.开始时间的记录具有以下格式:
@startDate:20151104101700-0800
@endDate:20151104111700-0800
...
@startDate:20151002151700-0800
@endDate:20151003151700-0800
Run Code Online (Sandbox Code Playgroud)
我只是想知道"15170-0800"这个部分代表什么.有人可以帮忙吗?
我用ggplot2在R中绘制一个数字.图中的图例有两行,但我想打开它们并将它放在一行中.我四处搜寻,发现这guide_legned()可能是要走的路.我尝试了几种不同的方法,唯一没有给出错误的方法是这样的:
fig <- ggplot(data, aes(y=y, x=x, shape=z))+
geom_point(size = 4)+
scale_shape_manual(values = c(0,1,2,3,4,6))+
geom_abline('somestuff in here')+
scale_fill_continuous(guide=guide_legend(nrow=1))+
annotate('somestuff in here')+
theme_bw()+
theme(legend.title = element_blank(),
panel.grid = element_blank(),
legend.position='top',
legend.key = element_blank())
Run Code Online (Sandbox Code Playgroud)
然而,传说仍然是2行.我想知道为什么guide_legend(nrow=1)不工作(即使没有错误).什么是正确的方法呢?谢谢!
我正在按照官方页面上的说明和“验证您的安装”步骤安装 Tensorflow 。
>>> sess = tf.Session()
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用此us 1.0.0 包来获取美国州名列表,但遇到一些我不太明白的事情。这是我的代码:
import us
lst= us.states.STATES_AND_TERRITORIES
type(lst) # output: list
type(lst[0]) # output: us.states.State
lst[0] # output: <State:Alabama>
'<State:Alabama>' == list[0] # output: False
Run Code Online (Sandbox Code Playgroud)
最后一行最令人困惑。为什么它是假的?我以为他们长得一模一样……
不管怎样,我的问题是,我如何使用这个包来制作州名称列表,以便我可以检查一个字符串是否是州名称,例如:
if 'string_to_check' in lst:
do something...
Run Code Online (Sandbox Code Playgroud) 我看到有从列表中删除的项目,包括使用几个主题remove(),pop()和del.但这些都不是我想要的,因为我想在删除项目时获得一个新列表.例如,我想这样做:
a = [1, 2, 3, 4, 5, 6]
<fill in > # This step somehow removes the third item and get a new list b and let
b = [1, 2, 4, 5, 6]
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?