返回介绍

resize

发布于 2021-06-12 09:43:38 字数 1109 浏览 1063 评论 0 收藏 0

此函数返回具有指定大小的新数组。 如果新大小大于原始大小,则包含原始条目的重复副本。 该函数采用以下参数。

numpy.resize(arr, shape)

Where,

Sr.No.参数和描述
1

arr

要调整大小的输入数组

2

shape

生成的数组的新形状

例子 (Example)

import numpy as np 
a = np.array([[1,2,3],[4,5,6]]) 
print 'First array:' 
print a 
print '\n'
print 'The shape of first array:' 
print a.shape 
print '\n'  
b = np.resize(a, (3,2)) 
print 'Second array:' 
print b 
print '\n'  
print 'The shape of second array:' 
print b.shape 
print '\n'  
# Observe that first row of a is repeated in b since size is bigger 
print 'Resize the second array:' 
b = np.resize(a,(3,3)) 
print b

以上程序将产生以下输出 -

First array:
[[1 2 3]
 [4 5 6]]
The shape of first array:
(2, 3)
Second array:
[[1 2]
 [3 4]
 [5 6]]
The shape of second array:
(3, 2)
Resize the second array:
[[1 2 3]
 [4 5 6]
 [1 2 3]]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文