Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168742
Image: ubuntu2004
import numpy as np
def posmax(A): pos=A.argmax() N=A.shape[0] #je suppose que A est carree lin=index/N col=mod(index,N) return(lin,col)
def system_lineaire(A,b): N=A.shape[0] # matrice carree* #on met des zero sur chaque colonne for j in range(0,N-1): c=abs(A[j:N,j]) #permutation indices p et j #abs est la val absolue p=j+c.argmax() #ne pas oublier ici le .copy() v=A[j,:].copy() A[j,:]=A[p,:] A[p,:]=v.copy() # fin de la permutation # permutation de b à ne pas oublier t=b[j] b[j]=b[p] b[p]=t pivot=A[j,j] for i in range(j+1,N): b[i]=b[i]-(A[i,j]/pivot)*b[j] A[i,:]=A[i,:]-(A[i,j]/pivot)*A[j,:] #resolution du système triangulaire for j in range(N-1,0,-1): pivot=A[j,j] for i in range(j-1,-1,-1): b[i]=b[i]-(A[i,j]/pivot)*b[j] A[i,:]=A[i,:]-(A[i,j]/pivot)*A[j,:] sol=b/A.diagonal() return(sol)
A=np.array ([[11.,2.,3.,4.],[5.,6.,7.,108.],[10.,11.,12.,13.],[34.,45.,46.,57.]]) Asauve=A.copy() b=np.array([2.,3.,4.,5.])
sol=system_lineaire(A,b) print(sol)
[-0.23176471 -3.97176471 4.18 -0.01176471]
np.dot(Asauve,sol)
array([ 2., 3., 4., 5.])
c=np.array ([[1,2,3],[-35,23,6],[-15,13,16]])
b=abs(c)
b
array([[ 1, 2, 3], [35, 23, 6], [15, 13, 16]])
b.argmax(1)
array([2, 0, 2])
np.argmax?

File: /sagenb/sage_install/sage-4.7/local/lib/python2.6/site-packages/numpy/core/fromnumeric.py

Type: <type ‘function’>

Definition: np.argmax(a, axis=None)

Docstring:

Indices of the maximum values along an axis.

a : array_like
Input array.
axis : int, optional
By default, the index is into the flattened array, otherwise along the specified axis.
index_array : ndarray of ints
Array of indices into the array. It has the same shape as a.shape with the dimension along axis removed.

ndarray.argmax, argmin amax : The maximum value along a given axis. unravel_index : Convert a flat index into an index tuple.

In case of multiple occurrences of the maximum values, the indices corresponding to the first occurrence are returned.

>>> a = np.arange(6).reshape(2,3)
>>> a
array([[0, 1, 2],
       [3, 4, 5]])
>>> np.argmax(a)
5
>>> np.argmax(a, axis=0)
array([1, 1, 1])
>>> np.argmax(a, axis=1)
array([2, 2])
>>> b = np.arange(6)
>>> b[1] = 5
>>> b
array([0, 5, 2, 3, 4, 5])
>>> np.argmax(b) # Only the first occurrence is returned.
1