numpy创建ndarray对象的三种方法

1.1.list转化

In [8]: import numpy as np

In [9]: a = [1,2,3,4]

In [10]: x1 = np.array(a)

In [11]: x1
Out[11]: array([1, 2, 3, 4]) In [12]: type(x1)
Out[12]: numpy.ndarray

1.2.numpy内的函数生存

In [13]: x2 = np.arange(11)

In [14]: x2
Out[14]: array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])

1.3.文件生存

01.csv文件如下

使用numpy的loadtxt方法打开

  • 第一个参数:文件名
  • delimiter:以什么分隔
  • skiprows:跳过的行
  • usecols:使用哪几列
  • unpack:默认False,表示是否把列分开
x = np.loadtxt('01.csv',delimiter=',',skiprows=1,usecols=(1,4,6),unpack=False)

显示结果

In [18]: x.shape
Out[18]: (242, 3)

把每列分开保存

In [24]: open,close,volume = np.loadtxt('01.csv',delimiter=',',skiprows=1,usecols=(1,4,6),unpack=True)

结果:

In [26]: open.shape
Out[26]: (242,)

1.4.numpy的常用函数

In [36]: c = np.random.randint(1,100,10)

In [37]: c
Out[37]: array([44, 26, 40, 87, 32, 82, 20, 70, 62, 14]) In [38]: c.min()
Out[38]: 14 In [39]: c.max()
Out[39]: 87 In [40]: c.mean()
Out[40]: 47.7 In [43]: y = np.sort(c) In [44]: y
Out[44]: array([14, 20, 26, 32, 40, 44, 62, 70, 82, 87])

1.numpy的用法的更多相关文章

  1. 数据分析-numpy的用法

    一.jupyter notebook 两种安装和启动的方式: 第一种方式: 命令行安装:pip install jupyter 启动:cmd 中输入 jupyter notebook 缺点:必须手动去 ...

  2. numpy常用用法总结

    numpy 简介 numpy的存在使得python拥有强大的矩阵计算能力,不亚于matlab. 官方文档(https://docs.scipy.org/doc/numpy-dev/user/quick ...

  3. numpy.where() 用法详解

    numpy.where (condition[, x, y]) numpy.where() 有两种用法: 1. np.where(condition, x, y) 满足条件(condition),输出 ...

  4. numpy.loadtxt用法

    numpy.loadtxt(fname, dtype=, comments='#', delimiter=None, converters=None, skiprows=0, usecols=None ...

  5. Python 关于数组矩阵变换函数numpy.nonzero(),numpy.multiply()用法

    1.numpy.nonzero(condition),返回参数condition(为数组或者矩阵)中非0元素的索引所形成的ndarray数组,同时也可以返回condition中布尔值为True的值索引 ...

  6. python3 numpy基本用法归纳总结

    安装numpy : pip install numpy numpy数组生成方法总结 In [4]: import numpy as np #使用列表生成一个一维数组 data = [1,2,3,4,5 ...

  7. python numpy 的用法—— bincount

    今天看脚本的时候遇到了几个不懂的用法,记录下来供日后查看: 1.numpy bincount 先上图: 如上所示:首先要求输入的数组不能包含负数: 该函数是计算非负元素的个数,如果数组中的最大值为10 ...

  8. Numpy学习四:numpy.power()用法

    numpy.power(n, x) 对数组n的元素分别求x次方.x可以是数字,也可以是数组,但是n和x的列数要相同.

  9. NumPy 基础用法

    NumPy 是高性能科学计算和数据分析的基础包. 它是 pandas 等其他各种工具的基础. 主要功能: ndarray 一个多维数组结构, 高效且节省空间 无需循环对整组数据进行快速运算的数学函数 ...

随机推荐

  1. n2n网络环境搭建

    目的:   实现家中nas,在任何环境ssh访问 方案:n2n v1 (原因稳定&兼容macbook) 开源地址: https://svn.ntop.org/svn/ntop/trunk/n2 ...

  2. Docker学习笔记:基础

    docker的概念 :docker是一个可供开发者在容器中 开发 部署 运行 应用的一个平台.通过使用Linux容器去部署应用的方式称为容器化. 基础概念 Images and Container i ...

  3. Anaconda的安装及使用

    总结的很清楚,做个记录. http://python.jobbole.com/86236/

  4. canvas用数组方式做出下雨效果

    效果图 1.做出canvas画布和声明一个用来存储雨滴的数组 var c=document.getElementById('myCanvas'); var ctx= c.getContext('2d' ...

  5. java -相关技术

    地址:      http://www.codeyyy.com/java/11-35-52.html

  6. -1.记libgdx初次接触

    学习一门技术最难的是开发环境变量配置和工具配置,以下为我初次接触libgdx时遇到的问题 几个难点记录下 gradle 直接用下到本地,然后放到d盘,链接到就行(gradle-wrapper.prop ...

  7. php类自动加载

    __autoload 新建一个index.php <?php $d = new z(); function __autoload($class) //自动捕获new的类名 { $file = $ ...

  8. 缓存为王-varnish

    2.varnish的软件清单 [root@centos69 ~]# rpm -ql varnish /etc/logrotate.d/varnish /etc/rc.d/init.d/varnish ...

  9. Cbv源码简单分析图

    重点:cbv源码的简单分析(有后续)

  10. Jquery操作文档标签

    1.插入动作 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...