numpy-创建array

目录

1.numpy.array

2. numpy.arange

3.numpy.empty

4.numpy.empty_like

5.numpy.eye

6.numpy.identity

7.numpy.ones

8.numpy.ones_like

9.numpy.zeros

10.numpy.zeros_like

11.numpy.full

12.numpy.full_like

13.numpy.fromfile


1.numpy.array

函数原型:

numpy.array(object, dtype=None, *, copy=True, order='K', subok=False, ndmin=0, like=None)

参数解释:

  • object:array_like。可以是list,ndarray等。
  • dtype:data-type, optional
  • copy:bool, optional。默认为true
  • ndmin:int,可选参数。指定至少维度

2. numpy.arange

函数原型:

numpy.arange([start, ]stop, [step, ]dtype=None, *, like=None)

如果只传1个参数,分别为stop参数

如果只传2个参数,分别为start,stop参数

如果传3个参数,分别为start,stop,step参数

3.numpy.empty

函数原型:numpy.empty(shape, dtype=float, order='C', *, like=None)

函数说明:Return a new array of given shape and type, without initializing entries.

4.numpy.empty_like

函数原型:numpy.empty_like(prototype, dtype=None, order='K', subok=True, shape=None)

函数说明:Return a new array with the same shape and type as a given array.

5.numpy.eye

函数原型:numpy.eye(N, M=None, k=0, dtype=<class 'float'>, order='C', *, like=None)

函数说明:返回一个2维矩阵,对角线是1,其他位置为0。N:int,输出行数。M:int,输出列数,默认为N

6.numpy.identity

函数原型:numpy.identity(n, dtype=None, *, like=None)

函数说明:单位矩阵,n*n,对角线为1,其他位置为0。

参数解释:n:int,输出行数与列数

7.numpy.ones

函数原型:numpy.ones(shape, dtype=None, order='C', *, like=None)

函数说明:返回全是1的矩阵

8.numpy.ones_like

函数原型:numpy.ones_like(a, dtype=None, order='K', subok=True, shape=None)

函数说明:返回与输入矩阵相同的shape和dtype的全是1的矩阵

9.numpy.zeros

numpy.zeros(shape, dtype=float, order='C', *, like=None)

10.numpy.zeros_like

numpy.zeros_like(a, dtype=None, order='K', subok=True, shape=None)

11.numpy.full

numpy.full(shape, fill_value, dtype=None, order='C', *, like=None)   

12.numpy.full_like

numpy.full_like(a, fill_value, dtype=None, order='K', subok=True, shape=None)

13.numpy.fromfile

函数原型:

numpy.fromfile(file, dtype=float, count=- 1, sep='', offset=0, *, like=None)

import numpy as np
np.random.seed(0)

arr = np.arange(3 * 4, dtype = np.int8).reshape((3, 4))
print(arr)
print(arr.dtype)
arr.tofile('arr.bin')

arr2 = np.fromfile('arr.bin', dtype = np.int8).reshape((3, 4))
print(arr2)



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值