Python Programming for Biology: Bioinformatics and Beyond



Download 7,75 Mb.
Pdf ko'rish
bet476/514
Sana30.12.2021
Hajmi7,75 Mb.
#91066
1   ...   472   473   474   475   476   477   478   479   ...   514
Bog'liq
[Tim J. Stevens, Wayne Boucher] Python Programming

bins, valRange,

density)

Given an input array of

values generates a histogram

(counts and edges arrays) by

counting values within range

data = [0.1, 0.5, 1.5,

1.3, 1.0]

hist = histogram(data, 3,

(0,3))

vals, edges = hist




bins. The

bins

can be


specified as a number of bins

or as a list of boundary

values. If unspecified the

value range is from the

minimum to maximum

values of the input. Option to

normalise the histogram so

its summation is one:

density=True.

print(vals)

# [2, 3, 0]

print(edges)

# [ 0., 1., 2., 3.]

hstack(arrays)

Combines a sequence (e.g.

list) of arrays into a larger

array by stacking them

column-wise, along their

first axis. For example,

combines 1D vectors into a

single long 1D vector.

v1 = array([0,1,2])

v2 = array([7,8,9])

v3 = hstack([v1, v2])

# array([0, 1, 2, 7, 8,

9])


inner(arry1,

arry2)


Calculates the inner product

of two arrays, scalars or one

of each. Equivalent to .dot()

for 1D vectors, but for 2D

and above the result is the

sum of the products over the

last axes (rather than last and

penultimate in matrix

multiplication).

m1 = array([[ 1, 2],

[-2,

0]])


m2 = array([[-1, 1],

[ 2,


3]])

m3 = inner(m1, m2)

# array([[ 1, 8],

# [ 2, -4]])

ix_(indices1,

indices2, …)

Given a list of indices for

each axis/dimension

generates a mesh of indices:

a tuple of arrays that can be

used to index the selected

rows, columns etc. of

another array. Can be used to

extract sub-matrices.

rows = [0,1]

cols = [0,2]

mesh = ix_(rows, cols)

a1 = array([[0, 1, 2],

[3,


4, 5],

[6,


7, 8]])

a2 = a1[mesh]

# array([[0, 2],

# [3, 5]])

max(array, axis)

or

a.max()



Gives the maximum values

of an array along a given

axis, or if no axis is specified

the maximum value in the

whole array.

m1 = array([[-1, 1],

[

2, 3]])


m1.max()

# 3


m1.max(axis=0)


# array([2, 3])

m1.max(axis=1)

# array([1, 3])

mean(array,



axis)

or

a.mean()



Gives the mean (average)

values of an array along a

given axis, or if no axis is

specified the mean value of

the whole array.

m1 = array([[-1, 1],

[

2, 3]])


m1.mean()

# 1.25


m1.mean(axis=0)

# array([0.5, 2.0])

mgrid[slice1,

slice2, …]

An N-dimensional grid

object which can be indexed

to generate multi-

dimensional ranges of

indices. Provides similar

functionality to range() over

multiple dimensions.

m = mgrid[0:3,0:3]

#array([[[0,0,0],

# [1,1,1],

# [2,2,2]],

# [[0,1,2],

# [0,1,2],

# [0,1,2]]])

min(array, axis)

or

a.min()


Gives the minimum values

of an array along a given

axis, or if no axis is specified

the minimum value in the

whole array.

m1 = array([[-1, 1],

[

2, 3]])


m1.min()

# -1


m1.min(axis=0)

# array([-1, 1])

m1.min(axis=1)

# array([-1, 2])

nonzero(arry)

or

a.nonzero()



Gives the positional indices

for elements in an array that

are non-zero, or true in a

Boolean sense.

a1 = array([[8, 0, 0],

[0,


0, 9]])

rows, cols = a1.nonzero()

# array([0, 1]), array([0,

2])


# Nonzero at (0,0) and

(1,2)


ones(sizes,

dtype)

Generates a new array, of

specified size, filled with

ones. The data type may be

specified, but otherwise

defaults to floating point.

The size can be an integer or

a tuple of integers, one for

ones(4, int)

# Ints: array([1, 1, 1,

1])

ones((2,3))



# 2 x 3 array

# array([[1.0, 1.0, 1.0],




each axis, specifying number

of rows, columns etc.

# [1.0, 1.0,

1.0]])


outer(arry1,

arry2)


Calculates the outer product

or tensor product of two

array vectors. The outer

product of two vectors will

create a matrix with elements

that are the product of the

elements from each vector,

where the first vector is

applied across rows and the

second across columns.

v1 = array([0,1,2])

v2 = array([7,8,9])

m = outer(v1,v2)

# array([[ 0, 0, 0],

# [ 7, 8,

9],


# [14, 16,

18]])


radians(degrees)

Converts an angle value in

degrees to radians: multiply

by π/180.

radians(120.0)

# 2.0943951023931953

ravel(arry)

or

a.ravel()



Creates a flattened, one-

dimensional version of an

array.

a = array([[0, 1, 2],



[3,

4, 5],


[6,

7, 8]])


a.ravel()

#

array([0,1,2,3,4,5,6,7,8])



reshape(arry,

sizes)


or

a.reshape(sizes)

Rearranges the elements of

an array to make a new array

with specified number of

positions along each axis

(rows, columns etc.).

a = array([1,2,3,4,5,6])

reshape(a, (2,3)) # Rows,

cols


# array([[1, 2, 3],

# [4, 5,

6]])

a.reshape(3,2)



# array([[1, 2],

# [3, 4],

# [5, 6]])

std(arry, axis)

or

a.std(axis)



Calculates the standard

deviation of the values in an

array along a specified axis.

If the axis is not specified the

standard deviation is over all

values, i.e. the array is

data = array([[0.1, 0.2,

0.4],


[1.5, 1.3, 1.0]])

data.std()

# 0.543905629069

data.std(axis=1)




flattened.

# array([0.12472191,

0.20548047])

sum(arry, axes)

or

a.sum(axes)



Calculates the summation of

the values in an array, along

a specified axis (or tuple of

axes). If no axis is specified

the summation is over all

values in the array.

data = array([[0.1, 0.2,

0.4],


[1.5, 1.3, 1.0]])

data.sum()

# 4.5

data.sum(axis=0)



# array([1.6, 1.5, 1.4])

var(arry, axis)

or

a.var(axis)



Calculates the variance of

the values in an array along a

specified axis. If the axis is

not specified the variance is

over all values, i.e. the array

is flattened.

data = array([[0.1, 0.2,

0.4],


[1.5, 1.3, 1.0]])

data.var()

# 0.295833333333

data.var(axis=1)

# array([0.01555556,

0.04222222])

vstack(arrays)

Combines a sequence (e.g.

list) of arrays into a larger

array by stacking them row-

wise, along their second axis.

For example, combines 1D

vectors into a 2D matrix.

v1 = array([0,1,2])

v2 = array([7,8,9])

m = vstack([v1, v2])

# array([[0, 1, 2],

# [7, 8,

9]])

zeros(sizes,



dtype)

Generates a new array, of

specified size, filled with

zeros. The data type may be

specified, but otherwise

defaults to floating point.

The size can be an integer or

a tuple of integers, one for

each axis, specifying number

of rows, columns etc.

zeros(5)

# Floats: 0.0, 0.0, 0.0,

0.0, 0.0

zeros(4, int)

# Ints: array([0, 0, 0,

0])


zeros((2,3))

# 2 x 3 array

# array([[0.0, 0.0, 0.0],

# [0.0, 0.0,

0.0]])


Download 7,75 Mb.

Do'stlaringiz bilan baham:
1   ...   472   473   474   475   476   477   478   479   ...   514




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish