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

  • SEARCH
  • Home
  • 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 8238449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:49:19+00:00 2026-06-07T19:49:19+00:00

I have a textfile, randomfile.txt , containing a lot of values separated with blankstep,

  • 0

I have a textfile, randomfile.txt, containing a lot of values separated with blankstep, basically one single long line of different numbers.

10 20 30 40 50 10 45 65.......

I’m using numpy.loadtxt to read all the values into python. What I want to do next is divide the long line of numbers into a 2-dimensional numpy array with four columns.

I want the array structure to be the following:

[10, 20, 30, 40]
[50, 10, 45, 65]

I have tried to use numpy.reshape to modify the array, but the problem is that the values are read-in as a single line of code.

I’d be thankful for suggestions on how to solve this, or tips of tutorials I could dig myself into.

  • 1 1 Answer
  • 0 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-06-07T19:49:21+00:00Added an answer on June 7, 2026 at 7:49 pm

    The following line :

    np.loadtxt("randomfile.txt", dtype=int).reshape((-1, 4))
    

    gets me the following output :

    array([[10, 20, 30, 40],
           [50, 10, 45, 65]])
    

    with your sample data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a textfile and on each line is a single word followed by
I have a textfile (.txt) on a server. It contains only one word i.e.
I have a textfile of rows of values, each field delimited by a single
I have a very large (500mb) csv file and another textfile containing one word
I have a textfile.txt like this: First Line Second Line Third Line Fourth Line
If I have a a textfile say file.txt and it contains random words like:
I have to write the data below to a textfile after replacing two values
I have a textfile with some values. textfile data line1row1 line1row2 55 line2row1 line2row2
I have a textfile encoded in UTF-16. Each line contains a number of columns
I have a text file, one thing on each line. I also have a

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.