一些i / o问题(Some i/o problems)
免责声明:这是一项任务。 如果你觉得我只是“请你为我做功课”让我知道,我会问一个更广泛的问题,或者只是给你一些提示,如果你能取悦。
好的,我有两套100个文件。 第一组称为cell_spks_n,其中n = 1,...,100,第二组称为cell_dirs_n,其中n = 1,...,100。 numpy的loadtxt将这些文件加载到5x8数组中,这是完美的。 我想加载这些并为它们做一些事情。 现在我的问题是命名所有这些文件 。 我想到制作两个名为dirs和spks的列表,并按顺序将数组存储在其中。 然而出了问题,它只附加了一个 numpy加载的元素,我不知道出了什么问题。
from numpy import * files = 100 for i in range(1, files+1): dirs = [] spks = [] if (0<i<9): dirs_name = 'neurondata/cell_dirs_00' + str(i) + '.txt' spks_name = 'neurondata/cell_spks_00' + str(i) + '.txt' dirs.append(loadtxt(dirs_name)) spks.append(loadtxt(spks_name)) elif (9<i<=99): dirs_name = 'neurondata/cell_dirs_0' + str(i) + '.txt' spks_name = 'neurondata/cell_spks_0' + str(i) + '.txt' dirs.append(loadtxt(dirs_name)) spks.append(loadtxt(spks_name)) else: dirs.append(loadtxt('neurondata/cell_dirs_100.txt')) spks.append(loadtxt('neurondata/cell_spks_100.txt')) # Fancy stuff gets done here
我认为将这些作为数组加载甚至可能是一个坏主意,我将不得不考虑我的索引来访问数据。 理想的情况是有某种循环,如下所示:
for i in range(1,files+1): spk_i = loadtxt('cell_spks_i') dir_i = loadtxt('cell_dirs_i')
思考?
编辑:我忘记了一些输出
如果我说
for item in spks: print item print shape(spks)
我得到了输出
[[ 25.287356 23.655914 22.988506 14.285714 2.3809524 4.3478261 19.354839 11.764706 ] [ 16.129032 26.666667 19.565217 7.2289157 5.8823529 13.861386 7.0588235 12.195122 ] [ 13.157895 16.86747 26.190476 29.62963 12.121212 12.307692 27.5 19.047619 ] [ 18.518519 25.396825 34.482759 14.814815 20.224719 9.4117647 6.6666667 21.686747 ] [ 32.55814 22.988506 26.506024 21.782178 13.114754 2.7777778 14.814815 8.6021505]] (1, 5, 8)
Disclaimer: This is for an assignment. If you feel I'm just "asking you to do my homework for me" let me know and I'll ask a more broad question, or just give me hints if you can please.
Ok so I've got two sets of 100 files. The first set is called cell_spks_n where n=1,...,100 and the second set is called cell_dirs_n, where n=1,...,100. numpy's loadtxt loads these files in a 5x8 array which is perfect. I want to load these all up and do some stuff to them. Now my issue is naming all these files. I thought of making two lists called dirs and spks, and storing the arrays in them sequentially. However something goes wrong and it only appends one element that numpy loads and I'm not sure what's going wrong.
from numpy import * files = 100 for i in range(1, files+1): dirs = [] spks = [] if (0<i<9): dirs_name = 'neurondata/cell_dirs_00' + str(i) + '.txt' spks_name = 'neurondata/cell_spks_00' + str(i) + '.txt' dirs.append(loadtxt(dirs_name)) spks.append(loadtxt(spks_name)) elif (9<i<=99): dirs_name = 'neurondata/cell_dirs_0' + str(i) + '.txt' spks_name = 'neurondata/cell_spks_0' + str(i) + '.txt' dirs.append(loadtxt(dirs_name)) spks.append(loadtxt(spks_name)) else: dirs.append(loadtxt('neurondata/cell_dirs_100.txt')) spks.append(loadtxt('neurondata/cell_spks_100.txt')) # Fancy stuff gets done here
I think it might even be a bad idea loading these as arrays which I'll have to mind my indexing to access the data. The ideal case would be to have some kind of loop that goes something like this:
for i in range(1,files+1): spk_i = loadtxt('cell_spks_i') dir_i = loadtxt('cell_dirs_i')
Thoughts?
Edit: I forgot to some output
If I say
for item in spks: print item print shape(spks)
I get as output
[[ 25.287356 23.655914 22.988506 14.285714 2.3809524 4.3478261 19.354839 11.764706 ] [ 16.129032 26.666667 19.565217 7.2289157 5.8823529 13.861386 7.0588235 12.195122 ] [ 13.157895 16.86747 26.190476 29.62963 12.121212 12.307692 27.5 19.047619 ] [ 18.518519 25.396825 34.482759 14.814815 20.224719 9.4117647 6.6666667 21.686747 ] [ 32.55814 22.988506 26.506024 21.782178 13.114754 2.7777778 14.814815 8.6021505]] (1, 5, 8)
原文:https://stackoverflow.com/questions/20052527
满意答案
最简单的方法。
import { Http } from '@angular/http'; export class CustomComponent implements OnInit { length: number; constructor(private http: Http){ this.http.request('www.url...',{method:'GET'}).map(response => response.json()).subscribe(result=>{ this.length=result.length; }); } }
Easiest method.
import { Http } from '@angular/http'; export class CustomComponent implements OnInit { length: number; constructor(private http: Http){ this.http.request('www.url...',{method:'GET'}).map(response => response.json()).subscribe(result=>{ this.length=result.length; }); } }
相关问答
更多即使元素JSON数组零长度?(JSON array zero length even with elements?)
如何通过IConfiguration了解JSON数组的长度?(How to know the length of JSON array via IConfiguration?)
JSON数组只给出“1”作为长度,不能循环(JSON array only gives “1” as length, cannot loop through)
找到json字符串的长度(Find length of json string)
计算JSON数组的长度并访问PHP中的json元素(Count the length of JSON array and access the json element in PHP)
如何获得JSON数组的长度?(How to get the length of JSON array?)
Json.NET:解析未知长度的对象数组(Json.NET: Parsing object array of unknown length)
JSON数组使用jQuery或javascript获取长度(JSON array get length using jQuery or javascript)
验证JSON数组长度(Validate JSON array length)
在Hugo模板中,如何检查JSON文件数组的长度?(In Hugo templates, how do you check length of JSON file array?)
相关文章
更多Hadoop的I/O
Hadoop I/O系统介绍
Hadoop1.0.4 HDFS I/O性能测试
Java中如何用I/O流读取一个Word文档的内容?
O2O
Bentley.STAAD.RCDC.V8i.04.01.01.03 1CD
I18n的一个问题
WiFi入口流量O2O微应用平台
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!