python123九宫格输入法_【python】numpy中的高效分块操作np.stride_tricks.as_strided

本文介绍了Python numpy库中用于高效分块操作的函数np.stride_tricks.as_strided,通过实例展示了如何使用该函数将9x9的数独数组转换为3x3x3x3的四维数组,同时对比了reshape操作的区别。
摘要由CSDN通过智能技术生成

最近看代码的时候看到了这么一个函数

np.stride_tricks.as_strided(x, shap, strides, subok, writeable)

Parameters:

x : ndarray

Array to create a new.

shape : sequence of int, optional

The shape of the new array. Defaults to x.shape.

strides : sequence of int, optional

The strides of the new array. Defaults to x.strides.

subok : bool, optional

New in version 1.10.

If True, subclasses are preserved.

writeable : bool, optional

New in version 1.12.

If set to False, the returned array will always be readonly. Otherwise it will be writable if the original array was. It is advisable to set this to False if possible (see Notes).

Returns:

view : ndarray

看个实际案例便可以明白如何使用:

# 来源:NumPy Cookbook 2e Ch2.9

import numpy as np

# 数独是个 9x9 的二维数组

# 包含 9 个 3x3 的九宫格

sudoku = np.array

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值