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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:36:12+00:00 2026-05-27T18:36:12+00:00

I have a loop that adds elements to a 1d array: for i in

  • 0

I have a loop that adds elements to a 1d array:

    for i in range(0, 1000):
        fvector[0, i] = function_value

after the loop finishes, I have a 1 x 1000 vector that I want to store in a multi-dimensional array fmatrix, which is 50 x 1000. I managed to do this using a loop and copying each element individually – but it is very slow. I’ve then tried to use slice to copy the whole vector in one go after the loop and then be ready to copy next vector at the next column. How do I make it go to the next column? I’ve tried:

    s=slice([i], None)
    fmatrix[s] = fvector

and various combinations for s, but I get error messages about setting an array element with a sequence, or invalid syntax.

I know this should be straight forward but I’m very new to python, numpy and arrays 🙁

  • 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-27T18:36:12+00:00Added an answer on May 27, 2026 at 6:36 pm

    Try this. Allocate the matrix, here zero-initialized for effect:

    >>> import numpy as np
    >>> fmatrix = np.zeros((50, 1000))
    

    Then index into it to obtain fvector:

    >>> fvector = fmatrix[0]
    

    Then assign to fvector‘s elements:

    >>> for i in xrange(1000):
    ...     fvector[i] = i
    

    If you now inspect fmatrix[0], the first row of fmatrix, you’ll find that it has been assigned to in the previous loop. That’s because the NumPy row indexing creates fvector as a view on fmatrix‘s first row. This saves you a copy.

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

Sidebar

Related Questions

I have an inline assembler loop that cumulatively adds elements from an int32 data
hey, this i have a loop that adds gathered strings and ints into an
I have a PHP loop that adds data into a table cell. However, I
I have a PHP loop that adds data into a table cell. However, I
Say I have a loop that creates ImageViews and adds them to a layout
I have a function that adds shopping cart data to an array of arrays.
I have a loop that reads each line in a file using getline() :
I have a loop that finds duplicate lines in a .ini file. I can
I have a loop that runs through a variety of websites and I'd like
I have a loop that runs for approx. 25 minutes i.e 1500 seconds. [100

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.