• Register
1 vote
498 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 75 views
75 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 7 views
7 views
Problem: typeerror: unsupported operand type(s) for +: 'nonetype' and 'str'
asked Feb 15 Ethan ross 1.8k points
1 vote
1 answer 68 views
68 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 142 views
142 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
0 answers 19 views
19 views
Using pip install for any module apparently on my Ubuntu 16.04 system with python 2.7.11+ throws this error: TypeError: unsupported operand type(s) for -=: 'Retry' and 'int' What is wrong with pip? How could I reinstall it, if necessary? Update: Full traceback is below ... File "/usr/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/util/retry.py", line 228, in increment total -= 1
asked Oct 24, 2020 psandprop 2.4k points
1 vote
1 answer 92 views
92 views
Problem : I am a student and I am trying to learn python. I like programming so trying my hand on Python but the code which I have written in Python is giving me very strange looking error shown as below for your reference. Error: unsupported operand type(s) for ... array1=[1,2,3,4,5]; encryptedArray=runEncrypt(array1,4); print(encryptedArray); Please guide me in fixing my above error in Python.
asked May 15, 2020 Martin K 6.6k points
1 vote
1 answer 169 views
169 views
Problem: Hi all This is a question from a noob who started coding a few hours back. print("Hello") print("name") print("hello") print("Let's do some math!") print(5 + "a") print("5 + 5") print("Thanks for playing along!") It says, &ldquo;typeerror: unsupported operand type(s) for +: 'int' and 'str'&rdquo; What does it mean?
asked Mar 9, 2020 Gavin 15.3k points
0 votes
1 answer 19 views
19 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 5.8k points
0 votes
1 answer 4 views
4 views
Problem: I wrote a simple program which approximates the evaluation of a definite integral using numerical integration. However, I am stumped when it comes to why I am getting the error in the title. Keep in mind that I haven't touched python in one and a half years so it might be something incredibly obvious that I'm missing, however I'd still be grateful if you could help me
asked 3 days ago Mashhoodch 9.1k points
0 votes
1 answer 22 views
22 views
Problem: I am unsure why I am getting this error count=int(input ("How many donuts do you have?")) if count <= 10: print ("number of donuts: " ) +str(count) else: print ("Number of donuts: many")
asked Feb 14 Mashhoodch 9.1k points