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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:38:15+00:00 2026-06-12T09:38:15+00:00

It seems quit trivial to me but I’m still missing an efficient and clean

  • 0

It seems quit trivial to me but I’m still missing an efficient and “clean” way to insert a series of element belonging to numpy array (as aa[:,:]) in a formatted string to be printed/written.
In fact the extended element-by-element specification syntaxes like:

formattedline= '%10.6f  %10.6f  %10.6f' % (aa[ii,0], aa[ii,1], aa[ii,2]) 
file1.write(formattedline+'\n')

are working.

But I have not found any other shorter solution, because:

formattedline= '%10.6f  %10.6f  %10.6f' % (float(aa[ii,:]))
file1.write(formattedline+'\n')

of course gives: TypeError: only length-1 arrays can be converted to Python scalars

or:

formattedline= '%10.6f  %10.6f  %10.6f' % (aa[ii,:]) 
file1.write(formattedline+'\n')

gives: TypeError: float argument required, not numpy.ndarray.
I have tried with iterators but with no success.

Of course this is interesting when there are several elements to be printed.

So: how can I combine iteration over numpy array and string formatted fashion?

  • 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-12T09:38:16+00:00Added an answer on June 12, 2026 at 9:38 am

    You could convert it to a tuple:

    formattedline = '%10.6f  %10.6f  %10.6f' % ( tuple(aa[ii,:]) )
    

    In a more general case you could use a join:

    formattedline = ' '.join('%10.6f'%F for F in aa[ii,:] )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've tried to the word quit on a single line but this seems to
When I call Application.Exit(), the app seems to quit, but the debugger remains attached
If you call: [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@http://test.com]]; it seems to automatically quit your app
Seems to be a problem that many people have, but all the answers I
Seems that This will be an easy question for you but this problem is
Seems, it's common task, but I haven't found solution. I need to calculate number
Following this writeup ... The compiled binary seems to work fine, but the installed
This is related to my previous question , but it seems I have another
This may seem trivial for most people but I am getting problems in determining
This seems like a bug in Rails to me, but there's probably not much

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.