Numpy Basics

转载:
https://morvanzhou.github.io/tutorials/data-manipulation/np-pd/

Numpy属性:

  • ndim维度
  • shape行数和列数
  • size元素个数
import numpy as np

array = np.array([[1,2,3],[2,3,4]])
print(array)

print('number of dim:',array.ndim)  # 维度
# number of dim: 2

print('shape :',array.shape)    # 行数和列数
# shape : (2, 3)

print('size:',array.size)   # 元素个数
# size: 6

Numpy创建array

a = np.array([2,23,4])  # list 1d
print(a)
# [2 23 4]

a = np.array([2,23,4],dtype=np.int)
print(a.dtype)
# int 64

np.arrange()


Numpy基本运算

np.dot()
sum()
min()
max()
argmin()
argmax()
mean()
average()
median()
cumsum()
diff()
nonzero()
sort()
clip()
transpose()


Numpy索引

A[2]
A[1][1]
A[1,1]
A[1,1:3]
A.flatten

Numpy array合并
np.vstack()
np.hstack()
np.newaxis()
np.concatenate()


Numpy array分割

np.split(A, 2, axis=1)
np.split(A, 3, axis=0)

Numpy copy & deep copy

你可能感兴趣的:(Numpy Basics)