• Register
1 vote
688 views

Problem:

I have been working on project. For that I wrote the code:

def For_me(Array,a):
    n = len(Array)

    for column in xrange(n-1):
        for row in xrange(column+1, n):
            xmult = Array[row][column] / Array[column][column]
            Array[row][column] = xmult
          
            for col in xrange(0, n):
                Array[row][col] = Array[row][col] - xmult*Array[column][col]
            a[row] = a[row]-xmult*a[column]


    print Array
    print a

print For_me([[2,3],[4,5]],[[6],[7]])

But it gives me error message:

TypeError: unsupported operand type(s) for -: 'list' and 'list'

Can anyone help me otto solve this?

10 7 2
6,060 points

Please log in or register to answer this question.

1 Answer

1 vote
 
Best answer

Answer:

The simple and the best way to solve your code is by importing numpy. So change your code as:

import numpy

def For_me(Array,a):
    n = len(Array)

    for column in xrange(n-1):
        for row in xrange(column+1, n):
            xmult = Array[row][column] / Array[column][column]
            Array[row][column] = xmult
          
            for col in xrange(0, n):
                Array[row][col] = Array[row][col] - xmult*Array[column][col]
            a[row] = a[row]-xmult*a[column]


    print Array
    print a
    return Array, a

print For_me((np.array([[2,3],[4,5]]),np.array([[6],[7]])))

Hope this may solve your problem .

Happy coding.

11 6 4
34,950 points

Related questions

1 vote
1 answer 151 views
151 views
Problem: For the following python program et some error messages. The code: def Yanwa(Array,a): n = len(Array) for column in xrange(n-1): for row in xrange(column+1, n): xmult = Array[row][column] / Array[column][column] Array[row][column] = xmult for col in ... not defined Typeerror: unsupported operand type(s) for -: 'list' and 'list' Can any one sort this problem and help me out to solve this?
asked Apr 27, 2020 samhaz 5k points
0 votes
1 answer 10 views
10 views
Problem: I wrote rock-paper-scissor game with python and I have error which I can't solve. please help. import random p1 = random.randint(0, 2) def choosing(): p = int(input("Rock: 0; Paper: 1; scissor: 2:")) if p < 0 or p > 2: print("\ ... , in <module> TypeError: unsupported operand type(s) for -: 'NoneType' and 'int' and error comes only when I input valid value after entering invalid value
asked May 3 jamuna1 30.2k points
0 votes
1 answer 93 views
93 views
Problem: typeerror: unsupported operand type(s) for +: 'nonetype' and 'str'
asked Feb 15 Ethan ross 2.7k points
1 vote
1 answer 100 views
100 views
Problem: I wrote the following program in python and it throws me the error message: Please enter your first number: 10 Please enter your secoend number: 5 Addition of your numbers 105 Traceback (most recent call last): File "ires.py", line 9, in <module> ... some wong output and then it throws the error message. Is there any problem in my program thats causing this error? Thanks in advance.
asked May 12, 2020 samhaz 5k points
1 vote
1 answer 241 views
241 views
Problem : I have recently started learning Python 3. I am beginner to the programming world. Please find below the code responsible for the error: a = "I know the %d types of people." % 10 Integer = "integer" do_not = "don't" b = "Those type of people ... below error: &ldquo;Typeerror: unsupported operand type(s) for %: 'nonetype' and 'tuple'&rdquo;. Kindly guide me in fixing my above error?
asked Apr 2, 2020 morrisBson 3.2k points
0 votes
1 answer 16 views
16 views
Question: I try to find Euclidean distance between csv file row elements. My csv file format is as following. A | B | C | D 1 0 0 2 2 1 1 0 3 0 0 1 First, the user enters an input. For example, if the user enters 1 the output will be [('1', '0')]. Then, second ... for your advance. return sqrt(sum(pow(a-b,2) for a, b in zip(x, y))) TypeError: unsupported operand type(s) for -: 'tuple' and 'tuple'
asked Apr 12 Atik03 26.5k points
1 vote
1 answer 15 views
15 views
Problem: Any ideas on what I need to do to fix this? unsupported operand type(s) for -: 'list' and 'list'
asked Mar 15 MUHAMMAD MUNEEB 83k points
0 votes
1 answer 157 views
157 views
Problem: How to I Solve this : unsupported operand type(s) for ** or pow(): 'list' and 'int' HELP! I need help understanding this : unsupported operand type(s) for ** or pow(): 'list' and 'int' Can someone please help solve this, I am new in python().
asked Mar 2 Mashhoodch 13k points
0 votes
1 answer 44 views
44 views
Problem: Hi there! I am a new programmer and recently I started working in Python. I am facing difficulty in getting used to the syntax in Python. I am working with lists. I was trying to run following code: mylist = [1,2,3,4]; number = 2 newlist = mylist - number ... ' I want to cancel the number &lsquo;2&rsquo; from this list. I do not know how I can do this. Can anybody here guide me please?
asked Dec 5, 2020 Code Learner 9.9k points
0 votes
1 answer 8 views
8 views
Problem: I'm trying to get a distance calculated in mm's with a for next loop in python for fusion360. The calculation gives an error: typeerror unsupported operand type(s) for ^: 'float' and 'float' The calulation is: distance = scale - (scale / 2^ (x/12)) I think it has ... int(scale - (float(scale / 2^ (x/12)) ) But all give me the dreaded typeerror.... Who can point me in the right direction?
asked May 4 anika11 32.2k points