Category Archives: Maths

Complex Number

Real numbers – 0,0.3,1,2,-5, symbols (pi,e)

let us assume sqrt(i) = -1, this imaginary number
Imaginary numbers – i,-i, pi i, e i

Combine real and imaginary number = Complex number

z = 5 + 3i , you can’t add these 2 numbers, so this is called complex number

|Ima
|
3|                   z (it is called complex plane)
2|
a   1|
—————————- Re
-2 -1 |0 1 2 3 4 5
-1|
-2|
-3|                b (complex plan)
-4|

a = -2 +i
b= 4- 3i

classify the complex number

2+ 3i + 7i**2 + 5i**3 + 9i**4

let us assume i**2 = -1, i**3 => i**2*i => -i, i**4 => i**2 * i**2 => -1* -1 => 1

2+ 3i + 7i**2 + 5i**3 + 9i**4 => 2+ 3i -7 – 5i + 9 =>  4 – 2i

Advertisement

Data Science Tools – NumPy

NumPy
Multidimensional arrays + matrix, mathematical functions useful for statistical analysis (mean,median, standard deviation)

Installation
C:\Python27\Scripts>easy_install numpy
throws error error: Setup script exited with error: Unable to find vcvarsall.bat
Download and install manually http://sourceforge.net/projects/numpy/files/

import numpy
numbers = [1,2,3,4,5]
print numpy.mean(numbers) #3.0
print numpy.median(numbers) #3.0
print numpy.std(numbers) # 1.41

NumPy arrays are different from python lists. Numpy much faster than Python lists directly.

import numpy as np
array = np.array([1, 4, 5, 8], float)  #[ 1.  4.  5.  8.]
#array indexing and slicing
print array[1] #4.0, array[:2] #[ 1.  4.]
array[1] = 5.0 #array[1] = 5.0

# a 2D array/Matrix , Matrix indexing and slicing

array  = np.array([[1, 2, 3], [4, 5, 6]], float)  # [[ 1.  2.  3.]  [ 4.  5.  6.]]
array [1][1] #5.0
array[1, :] #[ 4.  5.  6.]
array[:, 2] #[ 3.  6.]

#Arithmetic operations

array1 = np.array([1, 2, 3], float)
array2 = np.array([5, 2, 6], float)
array1 + array2 #[ 6.  4.  9.]
array1 - array2 #[-4.  0. -3.]
array1 * array2 #[  5.   4.  18.]

#Matrix arithmetic

array = np.array([[1, 2], [3, 4]], float)
array2 = np.array([[5, 6], [7, 8]], float)
array1 + array2 #[[  6.   8.] [ 10.  12.]]
array1 - array2 #[[-4. -4.] [-4. -4.]]
array1 * array2 #[[  5.  12.] [ 21.  32.]]

#Standard arithmetic operations

array1 = np.array([1, 2, 3], float)
array2 = np.array([[6], [7], [8]], float)
np.mean(array1) #2.0
np.dot(array1, array2) #[ 44.]

NumPy Dot

Digital sum/root

Digital sum – the sum of all its digits. (12345 => 1+2+3+4+5=>15).

Digital root (also repeated digital sum) – the sum of all its digits untill a single-digit number is reached.
12345 => 1+2+3+4+5 => 15 => 1+5 => 6

In other words, it is the remainder when the number is divided by 9.

12345/9 => 12339 with a remainder of 6 => 1371.66 (1371*9=>12339 +6 => 12345).

Casting Out 9’s (a fast to find digital root).
Ignore the digit 9 in the number or a 9 anywhere in the number.

129 => 12 (remove 9) => 3 (1+2+9 => 12 => 3).

12999999993 => 1+2+3 => 6 (1+2+9+9+9+9+9+9+9+9+3 => 78 => 15 => 6).

1234125678 => (cross it out 1+8,2+7,3+6,4+5), so remaining 1,2 => 1+2 => 3
=> 1+2+3+4+1+2+5+6+7+8 => 39 => 12=> 3.

What is the purpose of the Digital Sum?
when the numbers are added, subtracted, multiplied or divided; their digital sums will also be respectively added, subtracted, multiplied or divided. So, digital sums to check the accuracy of the answer (mostly for big numbers).

123456789 * 123456789 = 15241578750190521
0* 0 = 115515 => 1+1+5+5+1+5 => 18 => 9 => 0 (so it correct)

123456789 * 123456789 = 15241578750190522 (change last digit 1 to 2).
0* 0 = 115552 => 1+1+5+5+5+2 => 19 => 10 => 1 (so it is not correct).

But it won’t find all the mistakes, let us the above exmaple, added 0 end of the result

123456789 * 123456789 = 152415787501905210(added 0, answer is wrong, but digit sum is correct)
0* 0 = 115515 => 1+1+5+5+1+5 => 18 => 9 => 0 (so it correct).

Matrix

A Matrix is an array of numbers, 2 rows and 3 columns 2 X 3

6  4 24
1 -9 8

Adding (same as subtracting) – A matrix with 3 X 5 +  3 X 5, but 3 X 5 # 3 X 4 (the columns don’t match in size).

 3 8 + 4  0 => 3+4 8+0 => 7  8
 4 6   1 -9    4+1 6-9    5 -3

Negative

- 6  4 24 = -6 -4 -24
  1 -9 8    -1  9 -8

Read more of this post