0

First and foremost, I'm not a native english speaker (just to make that clear)

I have written a script for my numeric class in which i computed all necessary functions to pass my class. Now I want to implement everything into a GUI to make things easier.

For the whole testing I worked with a 'test' file to see what types the outputs are and so on. The file is called Numerik_Funktionen1 and is imported to every file im working on. Now here is the problem:

This is a class and function i've written:

class LR:

    def LR_zerlegung(self, A, b = 0.):
        '''
        splits Matrix A in L and R
        L = lower triangular matrix -> linke untere Dreiecksmatrix
        R = upper triangular matrix -> rechte obere Dreiecksmatrix 
        returns (L, R) as tupel
        '''
        self.A = np.copy(A) * 1.
        self.ALr = A * 1.
        self.n = len(self.A[0])
        self.b = b        

        self.L = np.eye(self.n)

        for k in range(self.n-1):
            for i in range(self.n)[k+1:self.n]:
                self.L[i, k] = self.ALr[i, k] / self.ALr[k, k]
                self.ALr[i, k] = 0

                for j in range(self.n)[k+1:self.n]:
                    self.ALr[i, j] = self.ALr[i, j] - self.L[i, k] * self.ALr[k, j]

        self.R = self.ALr

        print('Ax = b')
        print('A', '\n', self.A,"\n")
        print('b', '\n', self.b,"\n")
        print('L', '\n', self.L,"\n")
        print('R', '\n', self.R,"\n")
        return self.L, self.R

The problem I run into is best described with code (I now it's neither well written nor good looking code, sorry)

import Numerik_Funktionen1

a = input("a eingeben: ")
b = input("b eingeben: ")
array_from_string = [s.split(',') for s in a.split(';')]
array_from_string2 = [s.split(',') for s in b.split(';')]
c = np.asarray(array_from_string)
d = np.asarray(array_from_string2)
A = c.astype(int)
b = d.astype(int)

The input for a looks like this: 2,3;5,4 and for b 2;4

After the proceeding A is an array (array([[2, 3], [5, 4]])) and b as well (array([[2], [2]]))

The call of the function looks like this: Numerik_Funktionen1.LR.LR_zerlegung(A, b)

So far so good, but if I want to take the previously described function LR_zerlegung, it returns this: 'numpy.ndarray' object has no attribute 'A'

I don't know what I do wrong and why it won't correspond with the Numerik_Funktionen1. I know my question in not well formulated and im sorry for that in advance.

Thank you

Nico
  • 463
  • 5
  • 11
  • [What is the purpose of self?](https://stackoverflow.com/questions/2709821/what-is-the-purpose-of-self) should help you. – MB-F Dec 05 '17 at 12:00
  • Thank you, didn't really help but figured it out :) – Nico Dec 05 '17 at 19:34
  • Sorry that it did not help. Since you figured it out now, you see what `self` has to do with it, don't you? – MB-F Dec 06 '17 at 06:45
  • Acutally the problem had nothing to do with the `self`, but mor with how i loaded the module into my gui. I needed to take another step while loading it (First: `LR = Numerik_Funktionen1.LR(), Second: `LR.LR_Zerlegung(A, b)`) and just like that it worked :) Now the whole project is finished und I hope I'll pass my exams with it :) If you want to have a look at it, i could send you the files via PM? :) – Nico Dec 06 '17 at 15:33
  • `Numerik_Funktionen1.LR.LR_zerlegung(A, b)` is equivalent to `Numerik_Funktionen1.LR.LR_zerlegung(self=A, A=b)` but `Numerik_Funktionen1.LR().LR_zerlegung(A, b)` is equivalent to something like `Numerik_Funktionen1.LR.LR_zerlegung(self=instance_of_LR, A=A, b=b)`. Anyway, good luck with the exams :) – MB-F Dec 06 '17 at 15:44

0 Answers0