目录

reshape

此函数为数组提供了新形状而不更改数据。 它接受以下参数 -

numpy.reshape(arr, newshape, order')

Where,

Sr.No. 参数和描述
1

arr

要重新整形的数组

2

newshape

int或int的元组。 新形状应与原始形状兼容

3

order

对于C风格为'C',对于Fortran风格为'F','A'表示如果数组存储在类似Fortran的连续内存中则为Fortran,否则为C风格

例子 (Example)

import numpy as np
a = np.arange(8)
print 'The original array:'
print a
print '\n'
b = a.reshape(4,2)
print 'The modified array:'
print b

其产出如下 -

The original array:
[0 1 2 3 4 5 6 7]
The modified array:
[[0 1]
 [2 3]
 [4 5]
 [6 7]]
↑回到顶部↑
WIKI教程 @2018