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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:23:57+00:00 2026-06-17T10:23:57+00:00

I have an array which I’m doing some calculations on. The array begins as

  • 0

I have an array which I’m doing some calculations on. The array begins as

e = array([[1,2,1,3],
           [3,-1,-3,-1],
           [2,3,1,4]])

I modify it a bit to convert it to:

array([[  1,   2,   1,   3],
      [  0,  -7,  -6, -10],
      [  0,  -1,  -1,  -2]])

Then I run this code on it:

import numpy as np
from fractions import Fraction

def ref(x):
    dimension = x.shape
    row_counter = 1
    first_values = [x[i][row_counter] for i in range(dimension[0])]                               #gets a list of elements of the column
    first_values = [number != 0 for number in first_values]                                       #0 is a pivot element?
    if False in first_values:                                                                     
        true_index =  first_values.index(True); false_index =   first_values.index(False)
        if true_index > false_index:                                                               #not any more
            x[[false_index, true_index]] = x[[true_index, false_index]]

    for i in range(row_counter+1,dimension[0]):
        multiplier = Fraction(x[row_counter][row_counter], x[i][row_counter])**-1
        row1 = multiplier*x[row_counter]
        row1 = x[i]-row1
        print row1
        x[i] = row1   

return x

Running this returns:

[0 0 -1/7 -4/7]
array([[  1,   2,   1,   3],
         [  0,  -7,  -6, -10],
         [  0,   0,   0,   0]])

So the result should be

array([[  1,   2,   1,   3],
         [  0,  -7,  -6, -10],
         [  0, 0, -1/7, -4/7]])

It prints the correct row entry but it doesn’t get added to the array, and a row of zeroes is added instead. Could someone please tell me why? Thanks.

  • 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-17T10:23:58+00:00Added an answer on June 17, 2026 at 10:23 am

    In general, numpy arrays are homogeneous with specific types. For example:

    >>> a = np.array([1,2,3])
    >>> a
    array([1, 2, 3])
    >>> a.dtype
    dtype('int64')
    

    When you set an element or slice specifically, what you add gets coerced to the current dtype, so:

    >>> a[0] = 5
    >>> a
    array([5, 2, 3])
    

    but

    >>> a[0] = 4.3
    >>> a
    array([4, 2, 3])
    

    You can get upcasting when you’re not acting in-place and so numpy is going to have to make a copy (i.e. a new object) anyway:

    >>> a = np.array([1,2,3])
    >>> a + 4.3
    array([ 5.3,  6.3,  7.3])
    >>> (a + 4.3).dtype
    dtype('float64')
    

    In your case, you can get the behaviour you want if you start with a numpy array of dtype object:

    >>> e = np.array([[  1,   2,   1,   3],
    ...               [  0,  -7,  -6, -10],
    ...               [  0,  -1,  -1,  -2]], dtype=object)
    >>> 
    >>> ref(e)
    array([[1, 2, 1, 3],
           [0, -7, -6, -10],
           [0, 0, -1/7, -4/7]], dtype=object)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array which I retrieve from some other source. This array then
I have an array which one of the keys contains some HTML code. I
I have an array which looks like this: $arr = ( [0]=>Int(2) [1]=>Array( ....)
I have an array which looks like this: $data = array( array('timestamp' => 1312776000,
I have an array which contains 12 numbers and I want to save this
I have an array which contains another array Would I notate it this way?
I have an array which looks like this : selected_products[0]=[r1,7up,61,Albertsons] selected_products[1]=[r3, Arrowhead,78,Arrowhead ] selected_products[2]=[r8,
I have this array which is retrieved by a json_encode().When I execute $.getJSON('beta.php' ,
I have an array which have this structure: $queues[n] Array ( [id] => integer
I have this array which gets the last table from a database. However the

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.