views:

70

answers:

1

My code looks like this:

a = IO.readlines("input.txt").map { |line| Vector.[](line.split) }

Now I want to access a single component of the first vector within my a array. I'm writing the following to address a vector:

puts a[0]

The behavior is pretty much expected - I receive the following:

Vector[1.2357, 2.1742, -5.4834, -2.0735]

Now let's try to address a single component this way:

puts a[0][0]

and voila, I receive a list of all the vector components,like:

1.2357
2.1742
-5.4834
-2.0735

How come? Maybe the last attempt was wrong? How do I correctly address a scalar inside a vector within an array?

+3  A: 

Due to your code I think the array construction should be:

a = IO.readlines("input.txt").map { |line| Vector[*line.split] }
khelll