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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:11:01+00:00 2026-05-31T03:11:01+00:00

As an example: from numpy import * A = array([2/3., 4]) print A Gives

  • 0

As an example:

from numpy import *
A = array([2/3., 4])
print A

Gives

[ 0.66666667  4.        ]

How do I take the string:

S = "[ 0.66666667  4.        ]"

And convert S back into A using numpy calls only? I have a hackish solution in place but it seems that there should be a numpy builtin that does this. I looked at fromstring, but when I used it directly it gives me the error:

fromstring(S)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: string size must be a multiple of element size
  • 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-05-31T03:11:02+00:00Added an answer on May 31, 2026 at 3:11 am

    You need fromstring(S, sep=' '). You almost parsed the string as packed binary data instead of printable floats. The string should only contain numbers and the delimiter (space), so trim it to get rid of the brackets. E.g., S[1:-1].

    You probably know this but let’s spell it out: This may be handy for recovering the results of a computation (or recovering from a mistake), but it is not a good way to store and reload data. It is inconvenient and you lose precision in the conversion. Your functions should return an array instead of printing it out, and if you need to store data for use by a later program run, use a digital storage format (e.g., see the cPickle module or whatever numpy provides for the purpose– note that fromstring can also read packed binary data)

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

Sidebar

Related Questions

for example, there is a matrix: import numpy as np A = np.array([[ 8.
Example dataset (rows were randomly extracted from a much larger matrix) import numpy as
How can I import an array to python (numpy.arry) from a file and that
please consider this reproducible example: from PIL import Image import numpy as np import
For example: from datetime import <c-x><c-o>{list of modules inside datetime package}
I am using the example from TheElements sample code provided with the iPhone SDK
I'm trying to using numpy.lib.stride_tricks.as_strided to iterate over non-overlapping blocks of an array, but
I try to run #!/usr/bin/env python import os from numpy import * b= ones((3,
I'm trying to index large 3D arrays using a 2D array of indicies from
I am trying to replicate the border of a 2d numpy array: >>> from

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.