如何在python中访问矩阵的各个元素 [英] how to access the individual elements of a matrix in python

查看:1461
本文介绍了如何在python中访问矩阵的各个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的档案格式为


01" \t" 10.19" \t" 0.00\t 10.65

02" \t" 11.19\t 10.12\t 99.99


我需要从中获取单独的浮点数!

比如说。第一个是10.19 ..我想访问它并添加一个。

展开 | 选择 | Wrap | 行号

解决方案

有一种强大的方法可以在一行中完成所有操作,但是通过解释,首先使用split()将每一行分成单独的数据列表以便进一步操作。

展开 | 选择 | Wrap | 行号



我的档案格式为


01" \t" 10.19" \t" 0.00\t 10.65

02" \t" 11.19\t 10.12\t 99.99


我需要从中获取单独的浮点数!

比如说。第一个是10.19 ..我想访问它并添加一个。

展开 | 选择 | Wrap | 行号


这是我的档案!你可以看到第一列给出了位置,第二列是.etc是矩阵的一部分。我的问题在于。我必须编写一个代码来访问各个值。就像我说A [01]我应该有值0.00或说A [06]我应该有一个值3.46。或者C [04] = 3.67等我必须在每个元素中添加一个。你可以给代码添加一些。我的代码无效。


NA bap


PO ACGT


01 0.00 3.67 0.00 0.00


02 0.00 0.00 3.67 0.00

03 0.00 0.00 0.00 3.67


04 0.00 3.67 0.00 0.00


05 3.67 0.00 0.00 0.00


06 3.46 0.00 0.22 0.00


07 0.00 0.00 3.67 0.00


08 0.00 0.00 0.00 3.67

09 0.00 0.00 0.00 3.67


10 0.00 3.67 0.00 0.00


11 3.67 0.00 0.00 0.00


12 3.67 0.00 0.00 0.00


13 0.00 0.00 3.67 0.00

14 0.00 0.00 0.00 3.67

15 0.00 0.00 3.67 0.00

16 0.00 3.67 0.00 0.00


//

//


NA bcd

my file is of the form

01 "\t" 10.19 "\t" 0.00 "\t" 10.65
02 "\t" 11.19 "\t" 10.12 "\t" 99.99


and i need to access the individual floating point numbers from it!
say for ex. the first no is 10.19.. i want to access this and add one to it.

Expand|Select|Wrap|Line Numbers

解决方案

There are powerful ways to do this all in one line, but by way of explanation, start by using split() to separate each line into individual data lists for further manipulation.

Expand|Select|Wrap|Line Numbers


my file is of the form

01 "\t" 10.19 "\t" 0.00 "\t" 10.65
02 "\t" 11.19 "\t" 10.12 "\t" 99.99


and i need to access the individual floating point numbers from it!
say for ex. the first no is 10.19.. i want to access this and add one to it.

Expand|Select|Wrap|Line Numbers


THis is my file! AS u can see the first column gives the position,the second third ..etc are the part of the matrix.my problem here is that.I have to write a code to access the individual values.like if i say A[01] i should have the value 0.00 or say A[06] i should have a value 3.46. or C[04]=3.67 etc. and i have to add one to each of these elements.can you gimme the code. my code is not working.

NA bap

PO A C G T

01 0.00 3.67 0.00 0.00

02 0.00 0.00 3.67 0.00

03 0.00 0.00 0.00 3.67

04 0.00 3.67 0.00 0.00

05 3.67 0.00 0.00 0.00

06 3.46 0.00 0.22 0.00

07 0.00 0.00 3.67 0.00

08 0.00 0.00 0.00 3.67

09 0.00 0.00 0.00 3.67

10 0.00 3.67 0.00 0.00

11 3.67 0.00 0.00 0.00

12 3.67 0.00 0.00 0.00

13 0.00 0.00 3.67 0.00

14 0.00 0.00 0.00 3.67

15 0.00 0.00 3.67 0.00

16 0.00 3.67 0.00 0.00

//

//

NA bcd


这篇关于如何在python中访问矩阵的各个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆