是否可以保存一个numpy数组,将其附加到已经存在的npy文件中np.save(filename,arr,mode='a')?
我有几个函数必须遍历大数组的行.由于内存限制,我无法立即创建数组.为了避免一遍又一遍地创建行,我想创建每一行一次并将其保存到文件中,并将其附加到文件中的上一行.稍后我可以在mmap_mode中加载npy文件,在需要时访问切片.
我有一个numpy数组
a = [1,2,3]
Run Code Online (Sandbox Code Playgroud)
我想保存到.txt文件,使文件看起来像:
1 2 3
Run Code Online (Sandbox Code Playgroud)
如果我使用numpy.savetxt然后我得到一个文件,如:
1
2
3
Run Code Online (Sandbox Code Playgroud)
我想应该有一个简单的解决方案,任何建议?
我可以将二进制文件下载并保存到'Documents'文件夹中,并且自定义名称完全正常.
如果我只是将URL更改为"应用程序支持"文件夹而不是"文档"文件夹,则无法写入该URL,表明它不存在.
这是URL构造代码:
- ( NSURL * ) getSaveFolder
{
NSURL * appSupportDir = nil;
NSURL * appDirectory = nil;
NSArray * possibleURLs = [[NSFileManager defaultManager] URLsForDirectory:NSApplicationSupportDirectory inDomains:NSAllDomainsMask];
if ( [possibleURLs count] >= 1 )
{
appSupportDir = [possibleURLs objectAtIndex:0];
}
if ( appSupportDir != nil)
{
NSString * appBundleID = [[NSBundle mainBundle] bundleIdentifier];
appDirectory = [appSupportDir URLByAppendingPathComponent:appBundleID];
}
return appSupportDir;
}
Run Code Online (Sandbox Code Playgroud)
这是保存代码:
- ( void ) writeOutDataToFile:( NSData * )data
{
NSURL * finalURL = [self.rootPathURL URLByAppendingPathComponent:self.aFileName];
[data writeToURL:finalURL …Run Code Online (Sandbox Code Playgroud) 我没有在Django的在线文档中看到关于这个主题的任何内容.
我试图将对象列表保存到数据库,但我可以做的是遍历列表并在每个对象上调用save().
那么Django几次命中数据库了吗?或者Django会做一次批量保存吗?
我创建了一个位图,现在我想将该位图保存到某个目录.任何人都可以告诉我这是如何完成的.谢谢
FileInputStream in;
BufferedInputStream buf;
try {
in = new FileInputStream("/mnt/sdcard/dcim/Camera/2010-11-16_18-57-18_989.jpg");
buf = new BufferedInputStream(in);
Bitmap _bitmapPreScale = BitmapFactory.decodeStream(buf);
int oldWidth = _bitmapPreScale.getWidth();
int oldHeight = _bitmapPreScale.getHeight();
int newWidth = 2592;
int newHeight = 1936;
float scaleWidth = ((float) newWidth) / oldWidth;
float scaleHeight = ((float) newHeight) / oldHeight;
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleWidth, scaleHeight);
Bitmap _bitmapScaled = Bitmap.createBitmap(_bitmapPreScale, 0, 0, oldWidth, oldHeight, matrix, true);
Run Code Online (Sandbox Code Playgroud)
(我想将_bitmapScaled保存到SD卡上的文件夹中)
if request.method == 'POST':
userf = UsersModelForm(request.POST)
username = userf.data['username']
password = userf.data['password']
passwordrepeat = userf.data['passwordrepeat']
email = userf.data['email']
Run Code Online (Sandbox Code Playgroud)
我试过这个:
tempSalt = bcrypt.gensalt()
password = bcrypt.hashpw(password,tempSalt)
passwordrepeat = bcrypt.hashpw(passwordrepeat,tempSalt)
userf.data['password'] = password
userf.data['passwordrepeat'] = passwordrepeat
Run Code Online (Sandbox Code Playgroud)
但我得到了错误.如何更改保存前userf.data['password']和userf.data['passwordrepeat']保存前的值?
错误:
AttributeError at /register
This QueryDict instance is immutable
Request Method: POST
Request URL: http://127.0.0.1:8000/register
Django Version: 1.3.1
Exception Type: AttributeError
Exception Value:
This QueryDict instance is immutable
Exception Location: /usr/local/lib/python2.6/dist-packages/django/http/__init__.py in _assert_mutable, line 359
Python Executable: /usr/bin/python
Python Version: …Run Code Online (Sandbox Code Playgroud) 我有一个使用mPDF的页面,当你运行时在浏览器中显示PDF,它也可以从这里保存为PDF没问题.我想要发生的是当页面运行并生成PDF,页面在服务器上保存为PDF.
这是当前的代码:
<?php
include $_SERVER['DOCUMENT_ROOT'].'/include/seo-check/lib/WSAclient.php';
include $_SERVER['DOCUMENT_ROOT'].'/include/seo-check/lib/WSAParser.php';
$reportID= $_GET['reportid'];
$WSAclient = new WSAclient(WSA_USER_ID,WSA_API_KEY);
$result=$WSAclient->viewReport($reportID,WSA_SUBSCRIPTION_ID,'xml','EN');
unset($WSAclient);
ob_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PDF Report</title>
<!--Add your CSS here-->
</head>
<body>
<?php
echo WSAParser::viewReportResponse($result);
?>
</body>
</html>
<?php
$HTMLoutput = ob_get_contents();
ob_end_clean();
//Convert HTML 2 PDF by using MPDF PHP library
include $_SERVER['DOCUMENT_ROOT'].'/include/seo-check/lib/MPDF/mpdf.php';
$mpdf=new mPDF();
$mpdf->WriteHTML($HTMLoutput);
$mpdf->Output();
?>
Run Code Online (Sandbox Code Playgroud)
就像我说的那样输出PDF很好但是有人可以告诉我如何保存为PDF吗?
我需要在save()或update()之后或之前生成一个函数来调用,但我不知道该怎么做.我想我需要来自save()update()的回调,但我不知道该怎么办.谢谢
我试图使用numpy的savetxt函数将数据附加到文件.以下是最低工作示例
#!/usr/bin/env python3
import numpy as np
f=open('asd.dat','a')
for iind in range(4):
a=np.random.rand(10,10)
np.savetxt(f,a)
f.close()
Run Code Online (Sandbox Code Playgroud)
我得到的错误是关于错误类型的
文件"/usr/lib/python3/dist-packages/numpy/lib/npyio.py",第1073行,在savetxt fh.write中(asbytes(格式为%tuple(row)+换行符))TypeError:必须是str,不是字节
在python2中不会发生此错误,所以我想知道问题是什么.谁能帮我吗?
我希望能够在我与之交互后保存html页面的状态.
假设我单击一个复选框,或者javascript设置各种元素的值.
如何保存"javascript-rendered"页面?
谢谢.