Install Python

www.anaconda.com/

A leading open data science platform powered by Python

www.spyder-ide.org/

Free IDE that comes with Anaconda

jupyter.org/

Using real-time code, visualization, text creation and sharing of documents…

1. Variables and types

Variable assignment

x = 5
x
Copy the code

5

operation

x + 9 # add
Copy the code

14

x - 9 # reducing
Copy the code

4 –

x * 9 # take
Copy the code

45

x ** 9 # power
Copy the code

1953125

x % 9 # modulus
Copy the code

5

x / float(9) # in addition to
Copy the code

0.5555555555555556

Types and type conversions

Type conversion The sample type
str() ’59’, ‘3.14’, ‘True’ string
int() 5, 9 The integer
float() 5.9, 3.14 Floating point Numbers
bool() True, True, True Boolean

2. String (String)

help

help(str)
Copy the code
zh_string = "The best ai development ever."
zh_string
Copy the code

‘The best ai development’

String manipulation

zh_string * 2
Copy the code

‘The best AI development the best AI development’

zh_string + 'Here it is.'
Copy the code

‘The best AI development is here.’

'我' in zh_string
Copy the code

False

String method

zh_string.upper()
zh_string.lower()
zh_string.count('in')
zh_string.replace('in'.' is ')
zh_string.strip()
Copy the code

‘The best ai development’

3. List

a = 'is'
b = 'it'
zh_list = ['我'.'list', a, b]
zh_list2 = [[1.3.5.7], [2.4.6.8]]
Copy the code

Element selection

# subscript
zh_list[1] The index starts at 0, where the second element is taken
zh_list[- 1] # Last element
Copy the code

‘it’

# shard
zh_list[1:3] # index 1, 2
zh_list[1:] # index 1 and after
zh_list[:3] # before index 3
zh_list[:] # All/copy list
Copy the code

[‘ I ‘, ‘list ‘,’ yes ‘, ‘this ‘]

# child list
zh_list + zh_list
zh_list * 2
Copy the code

[‘ I ‘, ‘list ‘,’ yes ‘, ‘this ‘,’ I ‘, ‘list ‘,’ yes ‘, ‘this ‘]

# list method
zh_list = [1.3.5.7]
zh_list.index(3) Get the element subscript
zh_list.count(3) # count elements
zh_list.append(0) # append element
zh_list.remove(0) # remove element
del(zh_list[:2]) Delete the first 2 elements
zh_list.reverse() # reverse list
zh_list.extend([2.4.6]) # Extended list
zh_list.pop(- 1) Eject (remove and return) the specified index element
zh_list.insert(3.9) # add element at index position
zh_list.sort() # sort list
Copy the code

4. The library

Import libraries

import numpy
import numpy as np
Copy the code

Selective import

from sklearn import datasets
Copy the code

5. Numpy array

zh_list = [1.3.5.7]
zh_array = np.array(zh_list)
zh_2darray = np.array([[1.3.5.7], [2.4.6.8]])
Copy the code

Numpy array element selection

# subscript
zh_list[0] The index starts at 0
Copy the code

1

# section
zh_list[:2]
Copy the code

[1, 3]

# 2 dimensional array subscript
zh_2darray[:, 1]
Copy the code

array([3, 4])

Numpy array operation

zh_array > 3
Copy the code

array([False, False, True, True])

zh_array * 2
Copy the code

array([ 2, 6, 10, 14])

zh_array + np.array([9.8.7.6])
Copy the code

array([10, 11, 12, 13])

Numpy array function

other_array = np.array([5.5.5.5])
zh_array.shape # dimension
np.append(zh_array, other_array) # append array
np.insert(zh_array, 1.5) # insert element
np.delete(zh_array, [1]) # delete element
np.mean(zh_array) The mean #
np.median(zh_array) # the median
np.corrcoef(zh_array) # Correlation coefficient
np.std(zh_array) # standard deviation
Copy the code

2.23606797749979