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 8950571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:28:52+00:00 2026-06-15T13:28:52+00:00

This code is set up to read two columns of data, and then print

  • 0

This code is set up to read two columns of data, and then print the first column into the first numpy array and then the second column into the second numpy array.

def read2coldata(filename):

    import numpy
    b = []
    f = open(filename,"r")
    lines = f.readlines()
    f.close()
    for line in lines:
        a = line.split()
        for i in a:
            b.append(i)
    return (numpy.array(b[::2]),numpy.array(b[1::2]))

However this gives:

(array(['1.5', '8', '16', '17'], dtype='|S3'), array(['4', '5', '6', '6.2'], dtype='|S3'))

How do I get rid of the dtype="|S3" parts to just leave:

(array(["1.5","8","16","17"], array(["4","5","6","6.2"])
  • 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-15T13:28:53+00:00Added an answer on June 15, 2026 at 1:28 pm

    the dtype="S3" you don’t want to “go away”.
    When you print a numpy array it gives you the type of the data in it. it isn’t part of the data, it is information about how the data is stored and understood by the program.

    In your particular example, you read number, so you probably want to use them afterwards in computation or whatever, in which case you’ll want the data to be understood as number (floats in you case).

    For the moment they are stored as strings, and that’s why you see dtype="S3" which essentially means string type of size 3 or less. (IIRC)

    I suggest to you an alternative to your function : numpy.genfromtxt is a function to load data from a txt file into a numpy array.

    The documentation is quite good and you’ll find it very useful if you spend the 20 minutes to understand the parameters.

    array1 = numpy.genfromtxt('path_to_my_file.txt', usecols=0)
    array2 = numpy.genfromtxt('path_to_my_file.txt', usecols=1)
    

    This should get you started.

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

Sidebar

Related Questions

I have two sets of text files. First set is in AA folder. Second
I have this code to set up and check a cookie, and before a
I use this code to set the background. It do change the background, but
I have a problem with this is code: Set oXmlHTTP = CreateObject(Microsoft.XMLHTTP) oXmlHTTP.Open POST,
In theory, this code should set the new lock status to the users and
This code returns an error: AttributeError: can't set attribute This is really a pity
What is wrong with this code ? set<string> nk ; bitset<3> bs1(string(100)); nk.insert(bs1.to_string()); error:
I have this code, i'm trying to set the identity seed by a varable
I'm trying to set an image as the background using this code: root.setStyle(-fx-background-image: url('splash.jpg');
so I have this code for tabs in jquery, the href is set to

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.