**Memos on Python Scientific Computing** Nov 20, 2017 Back to Home > Categories > programming

A cheating sheet on Scipy, etc.

iPython

Qt and Pylab

$ ipython qtconsole –pylab=inline # old feature $ ipython –pylab requires matplotlib and PyQt for inline plotting

shortcuts of command history

Interacting

Bookmarks

Debug

    %debug
    u/d
    %pdb iX (X is variable)

Tricks

Numpy

Object

  1. based on ndarray
  2. basically, type in np is float64

Type

dtype: variable type

astype(np.newtype) changing the type to newtype

Para

Slice

changing of slice of an array will be broadcast

for copying, using array[:].copy()

index and slice, array[:,:,:]

x[1,2,…] is equivalent to x[1,2,:,:,:], x[…,3] to x[:,:,:,:,3] and x[4,…,5,:] to x[4,:,:,5,:]

Boolean index

  1. array ==/!=/ value giving a boolean list with the same length, here the express array |/& value is used as boolean index.

  2. array(boolean_list) selecting the true element and broadcasting.

data[data<0] = 0 # changing the negative elements to 0s

Fancy index

a([i:],[j:],[]…)

Function

b = np.fromfunction(f,(5,4),dtype=int)

Shape

Stack

Split

  1. No copy
  2. Shallow copy
  3. Deep copy

TBD `````````````````````````````````````

------------------------------------------ **Tags**