Show Menu
Cheatography

Numpy - Chopito Cheat Sheet (DRAFT) by

Intentaré poner todo lo visto de Numpy lo mejor posible _Se irá actualizando con el tiempo_

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Introd­uction

Import Numpy
import numpy as np
Version
np.version
Version number
np.ver­sio­n.v­ersion, np.__v­ers­ion__
Config­uration
np.sho­w_c­onfig()
Info
np.inf­o(n­p.add)
Size
a.size
Itemsize
a.itemsize
1D
a = np.array( [1, 2, 3] )
2D
a = np.array( [ [1], [2] ] )
3D
a = np.array( [ [ [1], [2] ], [ [3], [4] ] ] )
Empty
a = np.emp­ty(10)
Zero & Int
a = np.zer­os(10, int)
One & Str
a = np.one­s([4, 2], str)
Range
a = np.ara­nge(10)
Linspace
a = np.lin­spa­ce(0, 10, num=5)
Concat­enate
c = np.con­cat­ena­te((a, b), axis=0)
Sort & Reverse
b = np.sor­t(a­)[::-1]
Reshape
b = a.resh­ape­(3,2)
Filters
a[a < 5], a[b], a[a % 2 ==0], a[1:-1]
Operations
a + a, a.sum(), a.min(), a.max()
Dot
np.dot(a, b)
Random 0
rng = np.ran­dom.de­fau­lt_­rng()
Random 1
a = rng.in­teg­ers(10, size=(3, 4)
Random 2
b = np.ran­dom.ra­ndi­nt(10, size=10)
Random 3
c = np.ran­dom.rand()
Random 4
d = np.ran­dom.no­rma­l(13, 1, 15)
Resize
a.resi­ze(­filas, columnas, refche­ck=­false)
NaN & Is NaN & Infinity
np.nan, np.isnan, np.inf
Is +Infinity & Is -Infinity
np.isp­osi­nf(a), np.isn­egi­nf(a)
Is Complex
np.isc­omp­lex(a)
Is Real
np.isr­eal(a)
Is Scalar
np.iss­cal­ar(­13.13)
Tolerance
np.all­clo­se(a, b)
Greater & Greater equal
np.gre­ater(a, b), np.gre­ate­r_e­qual(a, b)
Less & Less equal
np.less(a, b), np.les­s_e­qual(a, b)
Full
np.ful­l(10, 5)
Identity
np.ide­nti­ty(3)
 

Introd­uction

Astype
a.asty­pe(­float)
Changing values
a[1:-1, 1:-1] = 0
Changing values 1
a[::2, ::2] = 1
Pad
np.pad(a, pad_wi­dth=1, mode='­con­stant', consta­nt_­val­ues=0)