Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 387407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:40:13+00:00 2026-05-12T15:40:13+00:00

As far as I understood, matrices are very inflexible to work with. Therefor, I’m

  • 0

As far as I understood, matrices are very inflexible to work with. Therefor, I’m trying to get an array of vectors do deal with. My needs are: to be able to add vectors and make arithmetical operations on their components. Writing the code below,

require 'matrix'

x = Matrix.rows( IO.readlines("input.txt").each {|line| line.split} )

puts x.row_vectors

ruby falls into an exception. Why?

matrix.rb:1265:in `to_s': undefined method `join' for "1.2357 2.1742 -5.4834 -2.0735":String (NoMethodError)

OK then, I’ve calmed down and tried another approach. I wrote:

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

But the only way I can access my vectors inside an array is adressing the second index:

puts a[0][0]

This means, that when I would like to access desired scalar inside a vector, I’ll will be forced to use the third index, like:

puts a[0][0][1]

So, the second question is – where the hell that second index comes from? How to get rid of it? Am I missing something when reading data into array?

  • 1 1 Answer
  • 4 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T15:40:14+00:00Added an answer on May 12, 2026 at 3:40 pm

    I can’t reproduce your first problem. Extracting what looks like input.txt, I can execute that first expression without an exception.

    As to the second question, your expression seems kind of complex. How about:

    b = IO.readlines("input.txt").map { |x| x.split(' ') }
    

    This will get you a “2D” array of arrays, and you will need only two subscripts. (As to your question about where did the extra array come from, you got one from the Array constructor, one from IO.readlines, and one from the Vector constructor . . . I think.)

    Or maybe:

    result = []
    IO.foreach('input.txt') { |ln| result << ln.split(' ') }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I saw a field text[] (text array) in Postgresql. As far as I understood,it
As far as I understood the static initialization block is used to set values
As far as I understood it, BigInts are usually implemented in most programming languages
As far as I understand Objective C / iOS is very dynamic language, so
I am learning about the builder pattern, and so far I understood that, it
As far as I have understood so far, every time I draw something in
As far as I understood, Vuforia is a good starting point for developing AR-Applications
I was reading about union in C from K&R, as far as I understood,
As far as I understood it is not possible to rise privileges within the
I am new python programmer,what I have understood so far,yield keyword returns an object

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.