首页 \ 问答 \ 一些i / o问题(Some i/o problems)

一些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;
});

}

}

相关问答

更多

相关文章

更多

最新问答

更多
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • Java中的不可变类(Immutable class in Java)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • EXCEL VBA 基础教程下载
  • RoR - 邮件中的动态主体(部分)(RoR - Dynamic body (part) in mailer)
  • 无法在Google Script中返回2D数组?(Can not return 2D Array in Google Script?)
  • JAVA环境变量的设置和对path , classpth ,java_home设置作用和目的?
  • mysql 关于分组查询、时间条件查询
  • 如何使用PowerShell匹配运算符(How to use the PowerShell match operator)
  • Effective C ++,第三版:重载const函数(Effective C++, Third edition: Overloading const function)
  • 如何用DELPHI动态建立MYSQL的数据库和表? 请示出源代码。谢谢!
  • 带有简单redis应用程序的Node.js抛出“未处理的错误”(Node.js with simple redis application throwing 'unhandled error')
  • 使用前端框架带来哪些好处,相对于使用jquery
  • Ruby将字符串($ 100.99)转换为float或BigDecimal(Ruby convert string ($100.99) to float or BigDecimal)
  • 高考完可以去做些什么?注意什么?
  • 如何声明放在main之后的类模板?(How do I declare a class template that is placed after the main?)
  • 如何使用XSLT基于兄弟姐妹对元素进行分组(How to group elements based on their siblings using XSLT)
  • 在wordpress中的所有页面的标志(Logo in all pages in wordpress)
  • R:使用rollapply对列组进行求和的问题(R: Problems using rollapply to sum groups of columns)
  • Allauth不会保存其他字段(Allauth will not save additional fields)
  • python中使用sys模块中sys.exit()好像不能退出?
  • 将Int拆分为3个字节并返回C语言(Splitting an Int to 3 bytes and back in C)
  • 在SD / MMC中启用DDR会导致问题吗?(Enabling DDR in SD/MMC causes problems? CMD 11 gives a response but the voltage switch wont complete)
  • sed没有按预期工作,从字符串中间删除特殊字符(sed not working as expected, removing special character from middle of string)
  • 如何将字符串转换为Elixir中的函数(how to convert a string to a function in Elixir)