Change language

# sciPy function stats.variation () | python

` scipy.stats.variation (arr, axis = None) ` calculates the coefficient of variation. It is defined as the ratio of the standard deviation to the mean.

Parameters:
arr: [array_like] input array.
axis: [int or tuples of int] axis along which we want to calculate the coefficient of variation.
-" axis = 0 coefficient of variation along the column.
-" axis = 1 coefficient of variation working along the row.

Results: Coefficient of variation of the array with values ​​along specified axis.

Code # 1: using option ()

 ` from ` ` scipy.stats ` ` import ` ` variation ` ` import ` ` numpy as np `   ` arr ` ` = ` ` np.random.randn (` ` 5 ` `, ` ` 5 ` `) `   ` print ` ` (` `" array : "` , arr)   ` # lines: axis = 0, columns: axis = 1 `   ` print ` ` (` ` "Variation at axis = 0:" ` `, variation (arr, axis ` ` = ` ` 0 ` `)) `   ` print ` ` (` ` "Variation at axis = 1:" ` `, variation (arr, axis ` ` = ` ` 1 ` `)) `

Exit:

` array: [[-1.16536706 -1.29744691 -0.39964651 2.14909277 -1.00669835] [0.79979681 0.91566149 -0.823054 0.9189682 -0.01061181] [0.9532622 0.38630077 -09090 70154086 0.79087801] [0.53553389 1.46409899 1.89903817 -0.35360202 -0.14597738] [-1.53582875 -0.50077039 -0.23073327 0.32457064 -0.43269088]] Variation at axis = 0: [-12.73042404 5.106391079] 5.77300406 1.29451485 -1.27228112] `

Code # 2: How to implement without changes ()

 ` import ` ` numpy as np `   ` arr ` ` = ` ` np.random.randn (` ` 5 ` `, ` ` 5 ` `) `   ` print ` ` (` ` "array:" ` `, arr) `   ` # this function works like a variation () ` ` cv ` ` = ` ` lambda ` ` x: np.std (x) ` ` / ` ` np.mean (x) `   ` var1 ` ` = ` ` np.apply_along_axis (cv, axis ` ` = ` ` 0 ` `, arr ` ` = ` ` arr) ` ` print ` ` (` ` "Variation at axis = 0:" ` `, var1) ` ` `  ` var2 ` ` = ` ` np.apply_along_a xis (cv, axis ` ` = ` ` 1 ` `, arr ` ` = ` ` arr) ` ` print ` ` (` ` "Variation at axis = 0:" ` `, var2) `

Exit:

` array: [[0.51268414 -1.93697931 0.41573223 2.14911168 0.15036631] [- 0.50407207 1.51519879 -0.42217231 -1.09609322 1.93184432] [-1.07727163 0.27195529 -0.1308108 -1.75406388 0.94046395] [1.23283059 -0.03112461 0.59725109 0.06671002 -0.97537666] [1.1233506 0.97658799 -1.10309113 -1.33142901 -0.28470146]] Variation at axis = 0: [3.52845174 7.40891024 -4.74078192 - 3.57928544 2.85092056] Variation at axis = 0: [5.04874565 4.22763514 -2.74104828 4.10772935 -8.24126977] `

## Shop

Learn programming in R: courses

\$FREE

Best Python online courses for 2022

\$FREE

Best laptop for Fortnite

\$399+

Best laptop for Excel

\$

Best laptop for Solidworks

\$399+

Best laptop for Roblox

\$399+

Best computer for crypto mining

\$499+

Best laptop for Sims 4

\$

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

PythonStackOverflow

Check if one list is a subset of another in Python

PythonStackOverflow

How to specify multiple return types using type-hints

PythonStackOverflow

Printing words vertically in Python

PythonStackOverflow

Python Extract words from a given string

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

PythonStackOverflow

Python os.path.join () method

PythonStackOverflow

Flake8: Ignore specific warning for entire file

## Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically