当前位置:网站首页>[numpy] array properties
[numpy] array properties
2022-07-27 20:53:00 【When camellia flowers bloom.】

Import numpy Data packets
# introduce Numpy library
import numpy as np1. Array dimension number query
ndarray.ndmin Query the dimensions of the array
import numpy as np
# Array dimensions
## Dimension for 1
arr1 = np.array([1,2,3])
arr1.ndim # 1
## Dimension for 2
arr2 = np.array([[1,2,3],[4,5,6]])
arr2.ndim # 2
## Dimension for 3
arr3 = np.array([
[[1,2,3],[4,5,6]],
[[7,8,9],[10,11,12]]
])
arr3.ndim # 32. Array shape query
ndarray.shape Query the shape of the array ( A few lines and columns ), The return value is a tuple , There are several elements in it, which represent a multi-dimensional array
import numpy as np
arr1 = np.array([1,2,3])
arr1.shape # (3,)
arr2 = np.array([[1,2,3],[4,5,6]])
arr2.shape # (2,3)
arr3 = np.array([
[[1,2,3],[4,5,6]],
[[7,8,9],[10,11,12]]
])
arr3.shape # (2,2,3)ndarray.shape You can also change the shape of the array
import numpy as np
arr4 = np.array([[1,2,3],[4,5,6]])
arr4.shape = (3,2)
arr4

arr4( After processing )

3. Modify array shape
.reshape function You can change the shape of the original array , Create a new array , Change the elements of the new array , The value of the corresponding element of the original array will also change
# NumPy Provides .reshape Function to adjust the size and shape of the array
import numpy as np
data = np.array([[1,2,3],[4,5,6]]) # array([[1, 2, 3],
# [4, 5, 6]])
data.shape # (2,3)
arr = data.reshape(6,) # array([1, 2, 3, 4, 5, 6])
arr.shape # (6,)
arr[0] = 437
arr # array([437, 2, 3, 4, 5, 6])
data # array([[437, 2, 3],
# [ 4, 5, 6]]).flatten function Flat can be achieved ( Convert multidimensional array into one-dimensional array )
import numpy as np
arr = np.array([
[[1,2,3],[4,5,6]],
[[7,8,9],[10,11,12]]
])
arr.ndim # 3
deal_arr = arr.flatten() # array([1,2,3,4,5,6,7,8,9,10,11,12])
deal_arr.ndim # 14. Query the number of array elements and the memory occupied
ndarray.size Query the number of array elements
ndarray.itemsize Query the memory size of each element in the array ( In bytes )
import numpy as np
arr = np.array([
[[1,2,3],[4,5,6]],
[[7,8,9],[10,11,12]]
])
# The number of elements in the array
arr.size # 12
# Memory occupied by each element
arr.itemsize # 4
# The data type of each element
arr.dtype # dtype('int32')
# Memory occupied by array
arr.itemsize * arr.size # 48
# Array of dtype by int8( A byte )
data1 = np.array([1,2,3,4,5], dtype = np.int8)
data1.itemsize # 1
# Array of dtype For now float64( Eight bytes )
data2 = np.array([1,2,3,4,5], dtype = np.float64)
data2.itemsize # 85. Element data type query
ndarray.dtype For return ndarray The element type of the object
import numpy as np
arr1 = np.array([[1,2,3],[4,5,6]])
arr1.dtype # dtype('int32')
arr2 = np.array([1.2, 2.3, 3.4])
arr2.dtype # dtype('float64')边栏推荐
- Swiftui view onReceive method receives "redundant" event resolution
- R语言使用t.test函数执行t检验验证总体均值是否是某个特定的值(从样本集推论总体均值)
- sql编码bug
- User and authority modify user password
- MYSQL设计优化生成列
- 用户和权限限制用户使用资源
- 程序中的地址如何转换?
- R语言使用dplyr包进行数据聚合统计计算滑动窗口统计值(Window Statistics)、计算滑动分组均值(mean)并合并生成的统计数据到原数据集中
- Technology blog and tutorial
- How to monitor the running status and usage of NVIDIA Jetson
猜你喜欢

UE5使用DLSS(超级采样)提升场景的 FPS 远离卡顿的优化方案

Using dataX to realize efficient synchronization of MySQL data

When adding RTSP devices to easycvr platform, what is the reason for the phenomenon that they are all connected by TCP?

从0开始写bootloader

Introduction to rk3399 platform introduction to proficient series (Introduction) 21 day learning challenge

People call this software testing engineer. You're just making a living (with HR interview Dictionary)

Introduction to JVs Foundation

创新案例 | 本地生活服务数字化,高德品牌升级的增长战略

Analysis on the optimization of login request in IM development of instant messaging mobile terminal

Xdc 2022 Intel technology special session: Intel Software and hardware technology builds the cornerstone of cloud computing architecture
随机推荐
Some contents related to cmsis-rtos
openresty lua-resty-core 使用
One week activity express | in simple terms, issue 8; Meetup Chengdu station registration in progress
To do the test, you have to go to the big factory and disclose the "hidden rules" of bat big factory recruitment internally
[program life] "stage summary" - unwilling to be ordinary
Hcip day 5
[Numpy] 数组属性
DJI内推码(一码一用,2022年7月26日更新)
MySQL基本查询和运算符
金仓数据库 Oracle 至 KingbaseES 迁移最佳实践 (4. Oracle数据库移植实战)
你了解数据同步吗?
【毕设教程】YOLOv7 目标检测网络解读
knife4j通过js动态刷新全局参数
一周活动速递|深入浅出第8期;Meetup成都站报名进行中
品牌列表案例
The variable "lattice" or class "lattice.latticeeasy" (matlab) is not defined
[Numpy] 数组索引和切片
面了个腾讯拿38K跳槽出来的,见识到了真正的测试天花板
JVs privatization deployment start failure handling scheme
Swiftui view onReceive method receives "redundant" event resolution