I just started to learn python, so I need some help.
I have closeparams.txt file, it has CSV structure:
3;700;3;10;1
6;300;3;20;1
9;500;2;10;5
I need read this file to 2 dimension array. a[i,j] where i - is row and j - is column
I searched but not found exactly samples. I will use this massive like this:
i=0
j=3
print a(i,j)
I suppose that display:
10
Or
i=2
j=1
print a(i,j)
I suppose that display:
500
I suggest to use numpy
if you want to deal with arrays. In your case:
import numpy
a = numpy.loadtxt('apaga.txt', delimiter=';')
print a[0,3]
You didn't specify how important will the array construct be for you, but Numpy is very, very powerful for complex tasks, and can be very lean to perform smaller, quick'n'dirty tasks in a compact, fast and readable way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With