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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:16:05+00:00 2026-06-08T10:16:05+00:00

A really stupid question, but I could not figure the right way.. A is

  • 0

A really stupid question, but I could not figure the right way..

  1. A is a 2 by 2 matrix, and B is a 2 by 1 matrix.
  2. In a 10 iterations loop, B_new=A*B. B_new is 2 by 1.
  3. Save B_new to an output matrix B_final after each iteration. So in the end, B_final is 2 by 10.

However, I have problem of adding B to B_new in a loop. Below is my code, can anyone give me some suggestions?

import numpy as np
a=np.ones(shape=(2,2))
b=np.ones(shape=(2,1))     
c_final=np.zeros(shape=(2,10)) 

for i in range(0,10):
    c=np.dot(a,b)
    b=c
    c_final[:,i]=c

Here is the error message:

    c_final[:,i]=c
ValueError: output operand requires a reduction, but reduction is not enabled
  • 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-08T10:16:06+00:00Added an answer on June 8, 2026 at 10:16 am

    The error you’re seeing is because when numpy broadcasts c_final[:,i] and np.dot(a,b) together it produces an array with shape (2,2), which then can’t be assigned to c_final[:,i] since it has a shape of (2,1). I think it’s much clearer if you just play around with it in the interpreter:

    >>> import numpy as np
    >>> a = np.ones((2,2))
    >>> b = np.ones((2,1))
    >>> c_final = np.zeros((2,10))
    >>> np.dot(a,b)
    array([[ 2.],
           [ 2.]])
    >>> np.dot(a,b).shape
    (2, 1)
    >>> c_final[:,0]
    array([ 0.,  0.])
    >>> c_final[:,0].shape
    (2,)
    >>> np.broadcast(c_final[:,0],np.dot(a,b)).shape
    (2, 2)
    

    The way around this is to flatten np.dot(a,b) by using np.squeeze or something similar so that when they are broadcast together they produce a 2 element array. For example:

    >>> c_final[:,0] = np.dot(a,b).squeeze()
    

    You’re not alone in finding the error message unhelpful. Someone filed a ticket about this about a year ago.

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

Sidebar

Related Questions

It looks like it is a stupid question, but i could not figure how
I'm not really into multithreading so probably the question is stupid but it seems
Really stupid question, sorry, but I can't find it on google (I'm sure it's
It seems to be really stupid question, I know. But anyway. Lats say, I
I apologize for the stupid question, but I feel like I've really struck a
I know this sounds like a stupid question, but I really don't see the
I'm really sorry. This must seem like an incredibly stupid question, but unless I
This must be a really stupid question, but I'm still very green when it
Ok. This is probably a really stupid question, but I'm going to ask it
Sorry, this is probably a really stupid question, but is it safe to run

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.