¡@

Home 

python Programming Glossary: rand

Animate quadratic grid changes (matshow)

http://stackoverflow.com/questions/10429556/animate-quadratic-grid-changes-matshow

matplotlib import pyplot a arange 25 a a.reshape 5 5 b 10 rand 5 5 matshow a b cmap cm.jet colorbar show This code produces.. arange 25 a a.reshape 5 5 time 10 for t in range time b 10 rand 5 5 print b matshow a b cmap cm.jet colorbar show This produces.. def generate_data a np.arange 25 .reshape 5 5 b 10 np.random.rand 5 5 return a b def update data mat.set_data data return..

find length of sequences of identical values in a numpy array

http://stackoverflow.com/questions/1066758/find-length-of-sequences-of-identical-values-in-a-numpy-array

of the array from pylab import threshold 7 print '.' d 10 rand 10000000 print '.' b d threshold print '.' durations for i in..

How to force errorbars to render last with Matplotlib

http://stackoverflow.com/questions/14003572/how-to-force-errorbars-to-render-last-with-matplotlib

matplotlib.pyplot as plt fig plt.figure ax plt.gca ax.plot rand 50 color '0.75' for j in range 122 ax.errorbar range 50 rand.. 50 color '0.75' for j in range 122 ax.errorbar range 50 rand 50 yerr .3 rand 50 plt.draw Hacky work around fig plt.figure.. for j in range 122 ax.errorbar range 50 rand 50 yerr .3 rand 50 plt.draw Hacky work around fig plt.figure ax plt.gca ax.plot..

How to access pandas groupby dataframe by key

http://stackoverflow.com/questions/14734533/how-to-access-pandas-groupby-dataframe-by-key

in a groupby object by the key With the following groupby rand np.random.RandomState 1 df pd.DataFrame 'A' 'foo' 'bar' 3 'B'.. object by the key With the following groupby rand np.random.RandomState 1 df pd.DataFrame 'A' 'foo' 'bar' 3 'B' rand.randn.. 1 df pd.DataFrame 'A' 'foo' 'bar' 3 'B' rand.randn 6 'C' rand.randint 0 20 6 gb df.groupby 'A' I can iterate..

Fast Way to slice image into overlapping patches and merge patches to image

http://stackoverflow.com/questions/16774148/fast-way-to-slice-image-into-overlapping-patches-and-merge-patches-to-image

import numpy as np import scipy import collections import random as rand def get_indices_for_un_patchify sImg sP step ''' creates.. as np import scipy import collections import random as rand def get_indices_for_un_patchify sImg sP step ''' creates indices.. axis 2 return img I call those functions here e.g. with a random image if __name__ '__main__' img np.random.randint 255 size..

Random weighted choice

http://stackoverflow.com/questions/2073235/random-weighted-choice

1 0.5 2 1.0 3 702 0.2 1 0.5 2 703 0.5 3 Then generate a random number and search for it in the list. def func id1 max cdfs.. search for it in the list. def func id1 max cdfs id1 1 0 rand random.random max for upper id2 in cdfs id1 if upper rand return.. for it in the list. def func id1 max cdfs id1 1 0 rand random.random max for upper id2 in cdfs id1 if upper rand return..

Equivalent of Numpy.argsort() in basic python?

http://stackoverflow.com/questions/3382352/equivalent-of-numpy-argsort-in-basic-python

seq key seq.__getitem__ Now the IPython session In 16 seq rand 10000 .tolist In 17 timeit f seq 100 loops best of 3 10.5 ms..

A weighted version of random.choice

http://stackoverflow.com/questions/3679694/a-weighted-version-of-random-choice

weighted version of random.choice I needed to write a weighted version of random.choice.. of random.choice I needed to write a weighted version of random.choice each element in the list has a different probability.. is what I came up with def weightedChoice choices Like random.choice but each element can have a different chance of being..

Generating movie from python without saving individual frames to files

http://stackoverflow.com/questions/4092927/generating-movie-from-python-without-saving-individual-frames-to-files

False ax.get_yaxis .set_visible False im ax.imshow rand 300 300 cmap 'gray' interpolation 'nearest' im.set_clim 0 1.. fig.set_size_inches 5 5 tight_layout def update_img n tmp rand 300 300 im.set_data tmp return im #legend loc 0 ani animation.FuncAnimation..

binning data in python with scipy/numpy

http://stackoverflow.com/questions/6163334/binning-data-in-python-with-scipy-numpy

a_upper b_end 0 mean_val mean a_range return mean_val data rand 100 bins linspace 0 1 10 binned_data n 0 for n in range 0 len.. and easier to use numpy.digitize import numpy data numpy.random.random 100 bins numpy.linspace 0 1 10 digitized numpy.digitize.. to use numpy.digitize import numpy data numpy.random.random 100 bins numpy.linspace 0 1 10 digitized numpy.digitize data..

Relationship between scipy and numpy

http://stackoverflow.com/questions/6200910/relationship-between-scipy-and-numpy

from numpy import oldnumeric from numpy import from numpy.random import rand randn from numpy.fft import fft ifft from numpy.lib.scimath.. oldnumeric from numpy import from numpy.random import rand randn from numpy.fft import fft ifft from numpy.lib.scimath.. oldnumeric from numpy import from numpy.random import rand randn from numpy.fft import fft ifft from numpy.lib.scimath import..

Possible to make labels appear when hovering over a point in matplotlib?

http://stackoverflow.com/questions/7908636/possible-to-make-labels-appear-when-hovering-over-a-point-in-matplotlib

import figure show import numpy as npy from numpy.random import rand if 1 # picking on a scatter plot matplotlib.collections.RegularPolyCollection.. figure show import numpy as npy from numpy.random import rand if 1 # picking on a scatter plot matplotlib.collections.RegularPolyCollection.. plot matplotlib.collections.RegularPolyCollection x y c s rand 4 100 def onpick3 event ind event.ind print 'onpick3 scatter..

Polar contour plot in matplotlib - best (modern) way to do it?

http://stackoverflow.com/questions/9071084/polar-contour-plot-in-matplotlib-best-modern-way-to-do-it

some sort of model and get some output # We'll just use rand for this example values.append rand theta np.radians azimuths.. # We'll just use rand for this example values.append rand theta np.radians azimuths values np.array values values values.reshape.. 0 70 10 r theta np.meshgrid zeniths azimuths values np.random.random azimuths.size zeniths.size # Plot... fig ax plt.subplots..