Numpy generates special matrix

import numpy as np
data=np.loadtxt("data",delimiter=",",dtype=float)
Special matrix Explanation
np.asarray(data) Copy data matrix

np.ones(n)

np.ones( (M, N) )

np.ones_like( data )

Generate a one-dimensional array of length n, all elements are 1
Generate a two-dimensional matrix with M rows and N columns, all elements are 1
Generate a matrix with the same shape as the matrix data, all elements are 1

np.zeros(n)

np.zeros( (M, N) )

np.zeros_like( data )

Generate a one-dimensional array of length n, all elements are 0
Generate a two-dimensional matrix with M rows and N columns, all elements are 0
Generate a matrix with the same shape as the matrix data, all elements are 0

np.empty(n)

np.empty(n,dtype)

np.empty(data)

Generate an uninitialized one-dimensional array of length n
Generate an uninitialized two-dimensional matrix with M rows and N columns
Generate an uninitialized matrix with the same shape as the matrix data
np.eye(n) Generate an n*n identity matrix (diagonal elements are 1, the rest are 0)

np.arange(n)

np.arange(begin, end)

np.arange(begin, end, step)

Generate a one-dimensional array from 0 to (n-1), the number of steps is 1
Generate a one-dimensional array from begin to (end-1), the number of steps is 1
Generate a one-dimensional array from begin to (end-step), the number of steps is step

 

Guess you like

Origin blog.csdn.net/weixin_43217427/article/details/107748110