程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Numpy & pandas quick start

編輯:Python

Numpy&Pandas

  • Numpy piece
    • Numpy establish array
    • Numpy attribute
    • Num Basic operation 1
    • Numpy Basic operation 2

Numpy piece

Numpy establish array

import numpy as np
# a = np.array([1,2,3], dtype =np.int )
# a = np.array([[1,2,3],[3,4,5]] , dtype =float ) # Setting precision Set up 64 Only use np.float64
# a = np.zeros((3,5),dtype = np.int64)
# a = np.ones((3,4), dtype = np.int64)
# a = np.empty((3,4), dtype = np.int16)
# a = np.empty((3,4))
# a = np.full((3,4),2) # Specify all values of the matrix 
# a = np.arange(10,20)
# a = np.arange(20)
# a = np.arange(20).reshape((5,4))
a = np.linspace(1, 5, 20).reshape((5, 4)) # Line segment , from 1 To 10 piecewise 
print(a)
print(a.dtype)
a.fill(2) # You can also use it directly numpy Medium fill fill 2
print(a)
# print(help(np.empty))

Numpy attribute

import numpy as np
a = np.array([[1, 2, 3], [5, 9, 8]])
print(a)
print("number of dim:", a.ndim) # dimension 
print("shape:", a.shape)
print("size:", a.size)

Num Basic operation 1

import numpy as np
#
# #a = np.array([1,11,1])
# a = np.array([[1,11,1],[2,3,4]])
#
#
# b = np.arange(6).reshape(3,2)
#
#
# print(a<5) # The judgment logic symbol directly outputs bool type 
# print(a ==5)
#
# print(a)
# print(b)
#
# #c = a*b // Number and number multiplication Premise : Homomorphic matrices 
# #c = b**2
# #c =a - b
# #c = a -b
# #c = np.dot(a,b) // matrix multiplication perhaps 
# #c = a.dot(b)
# #c = np.cos(a) * 100
#
#
# print(c)
a = np.random.random((2, 4))
# print(np.max(a))
# print(np.sum(a))
# print(np.min(a))
print(np.max(a, axis=0)) # axis Axis by 1 For the line 0 Column 
print(np.sum(a, axis=1))
print(np.min(a, axis=1))
print(a)

Numpy Basic operation 2

import numpy as np
a = np.arange(15, 3, -1).reshape((3, 4))
print(np.argmax(a)) # Maximum index argument of a function
print(np.argmin(a)) # Minimum index 
# Average ( It can also be set to calculate by row and column )
print(np.mean(a))
print(a.mean())
# The old version 
print(np.average(a))
# I won't support it 
# print(a.average)
# Median 
print(np.median(a))
# Add up the previous values 
print(np.cumsum(a)) # Cumulative sum The accumulation of and 
# Output is not 0 Rows and columns of 
print(np.nonzero(a))
# The difference between the two 
print(np.diff(a))
# Every line ( Column ) Sort 
print(np.sort(a, axis=0))
# Transposition 
print(np.transpose(a))
print(a.T.dot(a))
# Leave only values in the range 
print(np.clip(a, 5, 9))
print(a)

Updating —


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved