一些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
2023-03-04 20:03

满意答案

最简单的方法。

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?)

这是console.log如何在某些浏览器console.log工作的问题。 您可以查看使用console.log(JSON.stringify(response.key5))来获取时间点视图。 基本上, console.log记录了最高级别的东西,但是如果稍后再扩展其中一个,则会显示扩展它时的内容,而不是您记录时的内容。 所以, 当你在控制台中展开它之前, response.key5是空的,但是在事件被添加到它之前,它是空的。 这种行为相当松动。 例如,在Chrome上,当console.log...

如何通过IConfiguration了解JSON数组的长度?(How to know the length of JSON array via IConfiguration?)

您可以创建一个与您的结构匹配的类,如: public class User { public string UserName { get; set; } public string Email { get; set; } public string Password { get; set; } public TodoItem[] Todos { get; set; } } public class TodoItem { public string Todo...

JSON数组只给出“1”作为长度,不能循环(JSON array only gives “1” as length, cannot loop through)

假设您不希望更改数据结构,可以迭代数组,然后迭代其中每个对象的属性(然后访问名称): var champions = [{ "1":{ "name":"Aatrox", "role1":"Top", "role2":"Jungle"}, "2":{ "name":"Ahri", "role1":"Middle"}, "3":{ "name":"Akali", "role1":"Middle", "role2":"Top...

找到json字符串的长度(Find length of json string)

让我们从json字符串开始: var jsonString = '{"name":"John"}'; 你可以很容易地确定它的长度: alert("The string has "+jsonString.length+" characters"); // will alert 15 然后将其解析为一个对象: var jsonObject = JSON.parse(jsonString); JavaScript Object 不是 Array ,没有长度。 如果您想知道它有多少属性,您需要计算它...

计算JSON数组的长度并访问PHP中的json元素(Count the length of JSON array and access the json element in PHP)

你尝试过不同的网址/文件吗? 我准确地修改了你的代码,它100%工作。 确保php://input正确。 尝试将JSON存储在外部文件中并尝试链接到该文件。 编辑 尝试这个: $json = file_get_contents('something.json'); $arr = json_decode($json, true); $count = 0; for($i = 0; $i < count($arr['data']); $i++) { $count++; } echo $count...

如何获得JSON数组的长度?(How to get the length of JSON array?)

最简单的方法。 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=>{ th...

Json.NET:解析未知长度的对象数组(Json.NET: Parsing object array of unknown length)

您可以对someObjects使用dynamic 。 代码可能如下所示: using System; using System.Collections.Generic; using Newtonsoft.Json; public class RootObject { public string chatName { get; set; } public List<string> users { get; set; } public bool someBooleanValu...

JSON数组使用jQuery或javascript获取长度(JSON array get length using jQuery or javascript)

这与Object.keys(obj).length相同 ,但没有浏览器兼容性问题(我认为)。 关于什么: var obj = { yo: { a: 'foo', b: 'bar' } hi: { c: 'hello', d: 'world', e: 'json' } } var arr = [], len; for(key in obj) { arr.push(key);...

验证JSON数组长度(Validate JSON array length)

你的JSON响应实际上是一个对象,而不是一个数组。 您正在检查的数组是该对象中名为items的属性。 因此,无论您使用的是getDept ,您都应该使用getDept.items : $.getJSON("https://apex.oracle.com/pls/apex/mfajertest1/department/"+$x('P2_DEPT_NO').value, function(getDept) { console.log(getDept.items); if(getDep...

在Hugo模板中,如何检查JSON文件数组的长度?(In Hugo templates, how do you check length of JSON file array?)

您可以使用eq函数来比较长度: {{ if (eq ($json | len) 0) }} no data {{ else }} show posts {{ end }} You can use the eq function to compare the length: {{ if (eq ($json | len) 0) }} no data {{ else }} show posts {{ end }}

相关文章

更多

Hadoop的I/O

1. 数据完整性:任何语言对IO的操作都要保持其数据的完整性。Hadoop当然希望数据在存储和处理中不 ...

Hadoop I/O系统介绍

看过很多Hadoop介绍或者是学习的帖子和文章,发现介绍Hadoop I/O系统的很少。很多文章都会介 ...

Hadoop1.0.4 HDFS I/O性能测试

分布式RDF查询引擎的项目需要在节点之间传输中间结果,考虑HDFS可以作为一个备选的传输媒介,于是对H ...

Java中如何用I/O流读取一个Word文档的内容?

BufferedReader br = new BufferedReader(new FileRead ...

O2O

啥是O2O?一句两句话解释不清楚,行业也没有统一的定义,O2O的英文全拼是Online To Offl ...

Bentley.STAAD.RCDC.V8i.04.01.01.03 1CD

1、Bentley Multiframe Advanced V8i SS3 17.00.02.10 W ...

I18n的一个问题

升级了,2.2.2, 用了I18n. 问题来了。 以前model validation 出错的默认消 ...

WiFi入口流量O2O微应用平台

WiFi入口流量O2O微应用平台 随着智能手机一年比一年销量大好,传统的互联网的流量争夺战场已经转向 ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本