Python-Numpy(1)Array数组
来源:互联网 发布:网络拒绝接入如何破解 编辑:程序博客网 时间:2024/06/05 11:29
import numpyworld_alcohol = numpy.genfromtxt("world_alcohol.txt", delimiter=",")print(type(world_alcohol))
#The numpy.array() function can take a list or list of lists as input. When we input a list, we get a one-dimensional array as a result:vector = numpy.array([5, 10, 15, 20])#When we input a list of lists, we get a matrix as a result:matrix = numpy.array([[5, 10, 15], [20, 25, 30], [35, 40, 45]])print vectorprint matrix
#We can use the ndarray.shape property to figure out how many elements are in the arrayvector = numpy.array([1, 2, 3, 4])print(vector.shape)#For matrices, the shape property contains a tuple with 2 elements.matrix = numpy.array([[5, 10, 15], [20, 25, 30]])print(matrix.shape)
#Each value in a NumPy array has to have the same data type#NumPy will automatically figure out an appropriate data type when reading in data or converting lists to arrays. #You can check the data type of a NumPy array using the dtype property.numbers = numpy.array([1, 2, 3, 4])numbers.dtype
#When NumPy can't convert a value to a numeric data type like float or integer, it uses a special nan value that stands for Not a Number#nan is the missing data#1.98600000e+03 is actually 1.986 * 10 ^ 3world_alcohol
world_alcohol = numpy.genfromtxt("world_alcohol.txt", delimiter=",", dtype="U75", skip_header=1)print(world_alcohol)
uruguay_other_1986 = world_alcohol[1,4]third_country = world_alcohol[2,2]print uruguay_other_1986print third_country
vector = numpy.array([5, 10, 15, 20])print(vector[0:3])
matrix = numpy.array([ [5, 10, 15], [20, 25, 30], [35, 40, 45] ])print(matrix[:,1])
matrix = numpy.array([ [5, 10, 15], [20, 25, 30], [35, 40, 45] ])print(matrix[:,0:2])
matrix = numpy.array([ [5, 10, 15], [20, 25, 30], [35, 40, 45] ])print(matrix[1:3,0:2])
资料:http://www.superkingdom.cn
后面加:/bigdata
阅读全文
0 0
- Python-Numpy(1)Array数组
- Python-Numpy(2)Array数组操作
- Python Numpy的数组array和矩阵matrix
- Python中的二维数组(list与numpy.array)
- Python Numpy的数组array和矩阵matrix
- python中数组(numpy.array)的基本操作
- Python Numpy的数组array和矩阵matrix
- Python中的二维数组(list与numpy.array)
- Python Numpy Tutorials: 数组--1
- Numpy的array数组操作
- numpy的array数组操作
- python numpy:1 numpy.array和numpy.matrix常用函数使用
- Python Intro - Numpy array shape
- python Numpy中array详解
- python模块numpy之array()
- Python之数组(array)使用方法总结与Numpy中的数组用法
- Python之数组(array)使用方法总结与Numpy中的数组用法
- Python之数组(array)使用方法总结与Numpy中的数组用法
- 【正一专栏】继续看中国的韬光养晦下盘大棋
- 将jar文件加到Maven的local repository中
- 【HAOI2015】T2 树状数组
- Mac电脑怎么上传文件到CentOS服务器
- Maven提高篇系列之(一)——多模块 vs 继承
- Python-Numpy(1)Array数组
- Filter过滤器
- 深度学习与计算机视觉 看这一篇就够了
- 【HAOI2015】T1树形Dp
- Maven提高篇系列之(二)——配置Plugin到某个Phase(以Selenium集成测试为例)
- [题解]bzoj4825 HNOI2017单旋
- Maven提高篇系列之(三)——使用自己的Repository(Nexus)
- Linux CentOS 使用命令设置网络代理
- Maven提高篇系列之(四)——使用Profile