La funció numpy.sqrt(array[, out]) s'utilitza per determinar l'arrel quadrada positiva d'una matriu, per elements.
Sintaxi: numpy.sqrt() Paràmetres: matriu: [array_like] Valors d'entrada les arrels quadrades dels quals s'han de determinar. fora: [ndarray, opcional] Objecte de matriu alternatiu en el qual posar el resultat; si es disposa, ha de tenir la mateixa forma que arr . Devolucions: [ndarray] Retorna l'arrel quadrada del nombre en una matriu.
Codi #1:
Python 3
# Python program explaining> # numpy.sqrt() method> # importing numpy> import> numpy as geek> # applying sqrt() method on integer numbers> arr1>=> geek.sqrt([>1>,>4>,>9>,>16>])> arr2>=> geek.sqrt([>6>,>10>,>18>])> print>('square>->root of an array1 : ', arr1)> print>('square>->root of an array2 : ', arr2)> |
>
algorisme per a bfs
>
Codi #2:
Python 3
# Python program explaining> # numpy.sqrt() method> # importing numpy> import> numpy as geek> # applying sqrt() method on complex numbers> arr>=> geek.sqrt([>4>,>->1>,>->5> +> 9J>])> print>('square>->root of an array : ', arr)> |
>
>
Codi #3:
cadena java amb format
Python 3
# Python program explaining> # numpy.sqrt() method> # importing numpy> import> numpy as geek> # applying sqrt() method on negative element of real numbers> arr>=> geek.sqrt([>->4>,>5>,>->6>])> print>('square>->root of an array : ', arr)> |
>
>
Aquí teniu un exemple de codi per a numpy.sqrt() a Python:
Python 3
import> numpy as np> # Create a numpy array> arr>=> np.array([>1>,>4>,>9>,>16>,>25>])> # Calculate the square root of each element in the array> sqrt_arr>=> np.sqrt(arr)> # Print the resulting array> print>(sqrt_arr)> |
>
>
Sortida:
[1. 2. 3. 4. 5.]
Avantatges:
La funció numpy.sqrt() és una manera ràpida i eficient de calcular l'arrel quadrada d'una matriu o un valor únic a Python.
La funció numpy.sqrt() és útil per a molts càlculs matemàtics i aplicacions científiques, com ara el càlcul de distàncies, velocitats i acceleracions en física.
Desavantatges:
- És possible que la funció numpy.sqrt() no sigui prou precisa per a determinades aplicacions científiques que requereixen alts nivells de precisió.
- És possible que la funció numpy.sqrt() no sigui adequada per a tots els tipus de dades, com ara nombres negatius o complexos.
Punts importants:
- La funció numpy.sqrt() retorna l'arrel quadrada d'una matriu o un valor únic.
- La funció numpy.sqrt() es pot utilitzar tant en nombres reals com complexos.
- La funció numpy.sqrt() es pot utilitzar en combinació amb altres funcions NumPy per realitzar operacions matemàtiques més complexes.
- La funció numpy.sqrt() es pot utilitzar per normalitzar dades escalant-les a un interval d'unitats.
Llibres de referència:
El manual de Python for Data Science de Jake VanderPlas cobreix la biblioteca NumPy i les seves aplicacions en ciència de dades en profunditat, incloses funcions per a operacions matemàtiques com numpy.sqrt().
Numerical Python: A Practical Techniques Approach for Industry de Robert Johansson cobreix la biblioteca NumPy i les seves aplicacions en informàtica numèrica i informàtica científica, incloses funcions per a operacions matemàtiques com numpy.sqrt().
Python Data Science Essentials d'Alberto Boschetti i Luca Massaron cobreix la biblioteca NumPy i les seves aplicacions en ciència de dades en profunditat, incloses funcions per a operacions matemàtiques com numpy.sqrt().