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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:18:08+00:00 2026-06-13T07:18:08+00:00

Suppose you have this array: In [29]: a = array([[10, 20, 30, 40, 50],

  • 0

Suppose you have this array:

In [29]: a = array([[10, 20, 30, 40, 50], [14, 28, 42, 56, 70], [18, 36, 54, 72, 90]])

Out[30]: a
array([[ 0,  0,  0,  0,  0],
       [14, 28, 42, 56, 70],
       [18, 36, 54, 72, 90]])

Now divide the third row by the first one (using from future import division)

In [32]: a[0]/a[2]
Out[32]: array([ 0.55555556,  0.55555556,  0.55555556,  0.55555556,  0.55555556])

Now do the same with each row in a loop:

In [33]: for i in range(3):
            print a[i]/a[2]   
[ 0.55555556  0.55555556  0.55555556  0.55555556  0.55555556]
[ 0.77777778  0.77777778  0.77777778  0.77777778  0.77777778]
[ 1.  1.  1.  1.  1.]

Everything looks right. But now, assign the first array a[i]/a[2] to a[i]:

In [35]: for i in range(3):
            a[i]/=a[2]
   ....:     

In [36]: a
Out[36]: 
array([[0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0],
       [1, 1, 1, 1, 1]])

Alright, no problem. Turns out this is by design. Instead, we should do:

In [38]: for i in range(3):
            a[i] = a[i]/a[2]
   ....:     

In [39]: a
Out[39]: 
array([[0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0],
       [1, 1, 1, 1, 1]])

But that doesn’t work. Why and how can I fix it?

Thanks in advance.

  • 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-13T07:18:09+00:00Added an answer on June 13, 2026 at 7:18 am

    You can cast the whole array to a float array first:

    a = a.astype('float')
    a /= a[2]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose i have an array $x = (31,12,13,25,18,10); I want to reduce this array
Suppose I have an array like this: $array = array(a,b,c,d,a,a); and I want to
Suppose that I have a 2D array (matrix) in Java like this... int[][] MyMat
Suppose I have this feature branch foo. Now I want to merge it back
Hi I am using Mathematica 5.2. Suppose I have an array list like In[2]:=lst=Tuples[{0,1},4]
Suppose I have an array such as the one below. If I wanted to
Let's suppose I have this array (it is actually 255 long, values up to
suppose I have an array of 10 ints, and I'm using binary search to
Suppose I have this class: class MyClass(object): def uiFunc(self, MainWindow): self.attr1 = foo self.attr2
Suppose I have this table parent | child 1 2 1 3 2 4

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.