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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:53:30+00:00 2026-06-09T04:53:30+00:00

I have a code that goes through several iterations. In each iteration, the code

  • 0

I have a code that goes through several iterations. In each iteration, the code generates a numpy based array. I append the numpy based array to an existing binary .dat file. I use the following code to generate the data:

WholeData = numpy.concatenate((Location,Data),axis=0)  
# Location & Data are two numpy arrays
DataBinary = open('DataBinary.dat','ab')
WholeData.tofile(DataBinary)
DataBinary.close()

I am trying to read the whole binary file into an array. I am having the following difficulties:

  1. I tried the following code:

    NewData = numpy.array('f')
    File1 = open('DataBinary.dat','rb')
    NewData.fromstring(File1.read())
    File1.close()
    

    Error status:

    Traceback (most recent call last):
    File “”, line 1, in
    AttributeError: ‘numpy.ndarray’ object has no attribute ‘fromstring’

  2. I tried to use an array based array and then read the file into the array.

    from array import array
    File1 = open('DataBinary.dat','rb')
    NewData.fromstring(File1.read())
    File1.close()
    

However, NewData is erroneous, i.e., it is not same as WholeData. I guess that saving the data as numpy.array and reading it as array.array might not be a good option.

Any suggestion will be appreciated.

  • 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-09T04:53:32+00:00Added an answer on June 9, 2026 at 4:53 am

    I think that numpy.fromfile is what you want here:

    import numpy as np
    myarray = np.fromfile('BinaryData.dat', dtype=float)
    

    Also note that according to the docs, this is not the best way to store data as "information on precision and endianness is lost". In other words, you need to make sure that the datatype passed to dtype is compatible with what you originally wrote to the file.

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

Sidebar

Related Questions

I have code that sends web requests through two parallel for each loops. Will
I have a for loop that goes through each input with class=required , and
I have a code that goes something like: $cipher_alg = MCRYPT_RIJNDAEL_128; $decrypted_string = mcrypt_decrypt($cipher_alg,
I have code that generates a List<string[]> variable but can't quite figure out how
So far, I have some working code that goes into a list of servers
I'm at a complete loss here. I have a method that goes through a
I have a form that goes through an endless loop and processes data. When
Hey there. Basically, I have a batch-file, that goes through all model and texture
I have a simple jquery loop that goes through my form and sees if
I have a program that will analyzes source code. It can recursively go through

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.