__author__ = 'mare' l = list( range(0, 10) ) print( sum(l) ) print( sum(l, 100) ) print( max(l) ) print( min(l) ) print( abs(-11) ) #45 #145 #9 #0 #11 print( "-----" ) print( pow(2, 10) ) #2^10 print( pow(2, 10, 100) ) #(2^10)%10 print( divmod(10, 7) ) print( divmod(5.3, 2.1) ) #1024 #24 #(1, 3) #(2.0, 1.0999999999999996) print( round(152.394) ) print( round(152.394, 1) ) print( round(152.394, -1) ) #152 #152.4 #150.0 import math print( math.ceil(3.14 ) ) print( math.floor(3.14) ) print( math.trunc(3.14) ) #4 #3 #3 print("---") print( math.copysign(6.5, -0.0) ) print( math.fabs(-6.5) ) print( math.factorial(3.0) ) print( math.modf(-6.5) ) l = [3.14, 1.24, 5.23] print( math.fsum(l) ) #-6.5 #6.5 #6 #(-0.5, -6.0) #9.610000000000001 print("---") print( math.fmod(5.5, 3) ) print( 5.5%3 ) print( math.fmod(-5.5, 3) ) print( -5.5 % 3 ) #2.5 #2.5 #-2.5 #0.5 print( math.pow(2, 10) ) print( math.pow(1.5, 3) ) print( math.sqrt(2) ) #sqrt(2) print( math.exp(2) ) #e^2 print( math.log(math.e) ) #ln(e) #1024.0 #3.375 #1.4142135623730951 #7.38905609893065 #1.0 print("---") r = math.radians(30) print(math.sin(r)) r = math.radians(180) v = math.cos(r) print( v ) print( r == math.acos(v) ) print( math.degrees(r) ) #0.49999999999999994 #-1.0 #True #180.0 print("---") #fractions import fractions print( fractions.Fraction(4,16) ) print( fractions.Fraction(-6, 21) ) print( fractions.Fraction(3) ) #1/4 #-2/7 #3 f = fractions.Fraction(4,3) print(f) #4/3 f2 = fractions.Fraction(f) print(f2) #4/3 print("---") #special functions print( fractions.Fraction('6/21') ) print( fractions.Fraction('3.14') ) print( fractions.Fraction(' -0.34 ')) s = """ -0.34 """ print( fractions.Fraction(s) ) #2/7 #157/50 #-17/50 #-17/50 print("---") from fractions import Fraction print( Fraction.from_float(0.5) ) print( Fraction.from_decimal(4) ) #1/2 #4 print("---") from math import pi, cos from fractions import Fraction print( Fraction.from_float(pi) ) #884279719003555/281474976710656 print( Fraction.from_float( pi ).limit_denominator(100) ) #311/99 f = Fraction.from_float(3.14) print( f.__floor__() ) #3 import math print( math.floor(f) ) print( math.ceil(f) ) print( round(f) ) #3 #3 #4 #3 import fractions fractions.gcd(120, 180) fractions.gcd(0.5, 6) #60, 0.5 print("---") #decimal import decimal print( decimal.Decimal(3) ) print( decimal.Decimal('1.1') ) print( decimal.Decimal(str(1/7)) ) #decimal.Deciaml( (0,(3,1,4),-2) ) print( decimal.Decimal("-Infinity") ) print( decimal.Decimal('-0') ) print( decimal.Decimal('NaN') ) #3 #1.1 #0.14285714285714285 #-Infinity #-0 #NaN a, b = decimal.Decimal('3.14'), decimal.Decimal('0.4') print( a+b ) print( a-b ) print( a*b ) print( a/b ) print( a**b ) #3.54 #2.74 #1.256 #7.85 #1.580417606406722895935118558 a = decimal.Decimal('3.14') print( a*3 ) print( divmod(a, 2) ) print( round(a, 1) ) print( int(a) ) #9.42 #(Decimal('1'), Decimal('1.14')) #3.1 #3 print("---") rawData = '3.14|5.3|1.65|9|-1.28' l = [decimal.Decimal(x) for x in rawData.split('|') ] print(l) #[Decimal('3.14'), Decimal('5.3'), Decimal('1.65'), Decimal('9'), Decimal('-1.28')] print( max(l) ) print( min(l) ) print( sum(l) ) print( sorted(l) ) #9 #-1.28 #17.81 #[Decimal('-1.28'), Decimal('1.65'), Decimal('3.14'), Decimal('5.3'), Decimal('9')] from decimal import Decimal d = Decimal("3.14") print( d.sqrt() ) #1.772004514666935040199112510 print( d.exp() ) print( d.ln() ) #23.10386685872218278457908458 #1.144222799920161998805694448 d2 = Decimal("-1.414") print( d.compare(d2) ) print( d.copy_abs() ) print( d.copy_negate() ) print( d.copy_sign(d2) ) #1 #3.14 #-3.14 #-3.14 print( d2.is_signed() ) print( d.is_finite() ) print( d.is_infinite() ) print( d.is_zero() ) #True #True #False #False #random import random print( random.random() ) print( random.random() ) #0.7774163660360384 #0.7987333021579469 print( random.uniform(3, 4) ) #3.013465537004017 for i in range(3): print( random.gauss(1, 1.0) ) #0.07892791910471075 #0.49322741367164435 #0.6201914100688197 print( [random.randrange(20) for i in range(10) ]) #[0, 15, 11, 5, 17, 15, 0, 0, 11, 4] print( random.sample( range(20), 10 )) #[16, 4, 8, 0, 15, 10, 2, 19, 7, 13] print( [random.randrange(0,20,3) for i in range(5) ] ) #[18, 18, 18, 12, 12] print("---") l = list(range(10)) print(l) print( [random.choice(l) for i in range(3) ]) #[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] #[1, 0, 6] print( random.sample(l,3)) #[5, 4, 8] l = list( range(10) ) print( l ) random.shuffle(l) print( l ) #[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] #[2, 4, 1, 7, 3, 0, 8, 9, 5, 6] l = list( range(10) ) s = random.sample(l, 10) print( l, s) #[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] [9, 5, 6, 8, 7, 1, 3, 4, 0, 2]
3/03/2014
python study, math modules, example source code
Subscribe to:
Post Comments (Atom)
-
Logistic Classifier The logistic classifier is similar to equation of the plane. W is weight vector, X is input vector and y is output...
-
As you can see in the following video, I created a class that stitching n cameras in real time. https://www.youtube.com/user/feelmare/sear...
-
fig 1. Left: set 4 points (Left Top, Right Top, Right Bottom, Left Bottom), right:warped image to (0,0) (300,0), (300,300), (0,300) Fi...
-
Image size of origin is 320*240. Processing time is 30.96 second took. The result of stitching The resul...
-
* Introduction - The solution shows panorama image from multi images. The panorama images is processing by real-time stitching algorithm...
-
Created Date : 2011.10 Language : C/C++ Tool : Microsoft Visual C++ 2008 Library & Utilized : OpenCV 2.3 Reference : SIFT referenc...
-
OpenCV has AdaBoost algorithm function. And gpu version also is provided. For using detection, we prepare the trained xml file. Although...
-
In the YUV color format, Y is bright information, U is blue color area, V is red color area. Show the below picture. The picture is u-v col...
-
simply check below code and example result. . def image_grid ( imgs , rows , cols ): assert len ( imgs ) == rows * cols w , h...
-
I once wrote the following article. http://study.marearts.com/2014/04/opencv-study-mat-point-access-method.html This article is a sample c...
No comments:
Post a Comment