我在.ipynb文件中有一些代码,并且我不需要IPython Notebook的"交互"功能.我想直接从Mac终端命令行运行它.
基本上,如果这只是一个.py文件,我相信我可以从命令行执行python filename.py..ipynb文件有类似的东西吗?
我最近注意到我运行的旧版AWS CLI缺少我需要的一些功能:
$aws --version
aws-cli/1.2.9 Python/3.4.3 Linux/3.13.0-85-generic
Run Code Online (Sandbox Code Playgroud)
如何升级到最新版本的AWS CLI(1.10.24)?
编辑:
运行以下命令无法更新AWS CLI:
$ pip install --upgrade awscli
Requirement already up-to-date: awscli in /usr/local/lib/python2.7/dist-packages
Cleaning up...
Run Code Online (Sandbox Code Playgroud)
检查版本:
$ aws --version
aws-cli/1.2.9 Python/3.4.3 Linux/3.13.0-85-generic
Run Code Online (Sandbox Code Playgroud) 我使用aws cli使用以下命令(文档)列出s3存储桶中的文件:
aws s3 ls s3://mybucket --recursive --human-readable --summarize
Run Code Online (Sandbox Code Playgroud)
这个命令给我以下输出:
2013-09-02 21:37:53 10 Bytes a.txt
2013-09-02 21:37:53 2.9 MiB foo.zip
2013-09-02 21:32:57 23 Bytes foo/bar/.baz/a
2013-09-02 21:32:58 41 Bytes foo/bar/.baz/b
2013-09-02 21:32:57 281 Bytes foo/bar/.baz/c
2013-09-02 21:32:57 73 Bytes foo/bar/.baz/d
2013-09-02 21:32:57 452 Bytes foo/bar/.baz/e
2013-09-02 21:32:57 896 Bytes foo/bar/.baz/hooks/bar
2013-09-02 21:32:57 189 Bytes foo/bar/.baz/hooks/foo
2013-09-02 21:32:57 398 Bytes z.txt
Total Objects: 10
Total Size: 2.9 MiB
Run Code Online (Sandbox Code Playgroud)
但是,这是我想要的输出:
a.txt
foo.zip
foo/bar/.baz/a
foo/bar/.baz/b
foo/bar/.baz/c
foo/bar/.baz/d
foo/bar/.baz/e
foo/bar/.baz/hooks/bar …Run Code Online (Sandbox Code Playgroud) 我有一些从本地目录运行的.bat文件(例如C:\ Users\pozna001).但是,当我尝试使用cd F:\nrcs_project从其他位置运行.bat文件将目录更改为数据驱动器时,我看到命令提示符无法识别该cd命令.如何在命令提示符中更改目录,以便我可以从其他驱动器(即连接到服务器的数据驱动器)运行这些.bat文件?

我有一个工作grep命令,可以选择满足特定条件的文件.如何从grep命令中获取所选文件并将其输入cp命令?
以下尝试cp最终失败:
grep -r "TWL" --exclude=*.csv* | cp ~/data/lidar/tmp-ajp2/
Run Code Online (Sandbox Code Playgroud)
cp:在'/ home/ubuntu/data/lidar/tmp-ajp2 /'之后缺少目标文件操作数'尝试'cp --help'以获取更多信息.
cp `grep -r "TWL" --exclude=*.csv*` ~/data/lidar/tmp-ajp2/
Run Code Online (Sandbox Code Playgroud)
cp:无效选项 - '7'
我有一个混合类数据帧(数字和因子),我试图将整个数据帧转换为数字.以下说明了我正在使用的数据类型以及我遇到的问题:
> a = as.factor(c(0.01,0.02,0.03,0.04))
> b = c(2,4,5,7)
> df1 = data.frame(a,b)
> class(df1$a)
[1] "factor"
> class(df1$b)
[1] "numeric"
Run Code Online (Sandbox Code Playgroud)
当我尝试将整个数据框转换为数字时,它会改变数值.例如:
> df2 = as.data.frame(sapply(df1, as.numeric))
> class(df2$a)
[1] "numeric"
> df2
a b
1 1 2
2 2 4
3 3 5
4 4 7
Run Code Online (Sandbox Code Playgroud)
此站点上的先前帖子建议使用as.numeric(as.character(df1$a)),这对于一列非常有用.但是,我需要将此方法应用于可能包含数百列的数据框.
将整个数据帧从因子转换为数字,同时保留数字十进制值,我有哪些选择?
下面是我想产生其中输出a和b是数字:
a b
1 0.01 2
2 0.02 4
3 0.03 5
4 0.04 7
Run Code Online (Sandbox Code Playgroud)
我已阅读以下相关帖子,但它们都不直接适用于此案例:
我试图使用带有TensorFlow后端的keras来预测图像中的特征.具体来说,我试图使用keras ImageDataGenerator.该模型设置为运行4个时期并运行良好,直到它失败并出现MemoryError的第4个时期.
我在运行Ubuntu Server 16.04 LTS(HVM),SSD卷类型的AWS g2.2xlarge实例上运行此模型.
训练图像是256x256 RGB像素块(8位无符号),训练掩码是256x256单波段(8位无符号)平铺数据,其中255 = =感兴趣的特征,0 ==其他所有.
以下3个函数是与此错误相关的函数.
我该如何解决这个MemoryError?
def train_model():
batch_size = 1
training_imgs = np.lib.format.open_memmap(filename=os.path.join(data_path, 'data.npy'),mode='r+')
training_masks = np.lib.format.open_memmap(filename=os.path.join(data_path, 'mask.npy'),mode='r+')
dl_model = create_model()
print(dl_model.summary())
model_checkpoint = ModelCheckpoint(os.path.join(data_path,'mod_weight.hdf5'), monitor='loss',verbose=1, save_best_only=True)
dl_model.fit_generator(generator(training_imgs, training_masks, batch_size), steps_per_epoch=(len(training_imgs)/batch_size), epochs=4,verbose=1,callbacks=[model_checkpoint])
def generator(train_imgs, train_masks=None, batch_size=None):
# Create empty arrays to contain batch of features and labels#
if train_masks is not None:
train_imgs_batch = np.zeros((batch_size,y_to_res,x_to_res,bands))
train_masks_batch = np.zeros((batch_size,y_to_res,x_to_res,1))
while True:
for i in range(batch_size):
# choose random index in …Run Code Online (Sandbox Code Playgroud) 我希望根据字符串中的前三个字符对列表中的类似项进行分组.例如:
test = ['abc_1_2', 'abc_2_2', 'hij_1_1', 'xyz_1_2', 'xyz_2_2']
Run Code Online (Sandbox Code Playgroud)
如何根据第一组字母(例如'abc')将上述列表项分组?以下是预期输出:
output = {1: ('abc_1_2', 'abc_2_2'), 2: ('hij_1_1',), 3: ('xyz_1_2', 'xyz_2_2')}
Run Code Online (Sandbox Code Playgroud)
要么
output = [['abc_1_2', 'abc_2_2'], ['hij_1_1'], ['xyz_1_2', 'xyz_2_2']]
Run Code Online (Sandbox Code Playgroud)
我试过用它itertools.groupby来完成这个没有成功:
>>> import os, itertools
>>> test = ['abc_1_2', 'abc_2_2', 'hij_1_1', 'xyz_1_2', 'xyz_2_2']
>>> [list(g) for k.split("_")[0], g in itertools.groupby(test)]
[['abc_1_2'], ['abc_2_2'], ['hij_1_1'], ['xyz_1_2'], ['xyz_2_2']]
Run Code Online (Sandbox Code Playgroud)
我查看了以下帖子但没有成功:
如何合并列表中的类似项目.该示例使用对我的示例过于复杂的方法对类似项(例如'house'和'Hose')进行分组.
如何在Python列表中将等效项组合在一起?.这是我找到列表理解的想法.
我只需从文件名中提取数字,例如:
GapPoints1.shp
GapPoints23.shp
GapPoints109.shp
如何使用Python从这些文件中提取数字?我需要把它合并到一个for循环中.
我正在尝试复制 AWS CLIls命令以递归地列出 AWS S3 存储桶中的文件。例如,我将使用以下命令递归列出“location2”存储桶中的所有文件。
aws s3 ls s3://location2 --recursive
Run Code Online (Sandbox Code Playgroud)
适用于 Python 的 AWS 开发工具包(即boto3)相当于什么aws s3 ls s3://location2 --recursive?