zoukankan      html  css  js  c++  java
  • NumPy ndarray creation

    原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/12244066.html

    ndarray - A Multidimensional Array Object

    One of the key features of NumPy is its N-dimensional array object, or ndarray, which is a fast, flexible container for large datasets in Python. Arrays enable you to perform mathematical operations on whole blocks of data using similar syntax to the equivalent operations between scalar elements.

    e.g

    An ndarray is a generic multidimensional container for homogeneous data; that is, all of the elements must be the same type.

    Every array has a shape, a tuple indicating the size of each dimension, and a dtype, an object describing the data type of the array:

    ndarray - attributes

    Creating ndarrays

    The easiest way to create an array is to use the array function. This accepts any sequence-like object (including other arrays) and produces a new NumPy array containing the passed data.

    In addition to np.array, there are a number of other functions for creating new arrays. As examples, zeros and ones create arrays of 0s or 1s, respectively, with a given length or shape. empty creates an array without initializing its values to any particular value. To create a higher dimensional array with these methods, pass a tuple for the shape

    Note: It’s not safe to assume that np.empty will return an array of all zeros. In some cases, it may return uninitialized “garbage” values.

    arange is an array-valued version of the built-in Python range function:

    arange 或 linspace 可以很方便地创建连续数组,起到的作用都是一样的,都是创建等差数组。

    arange 类似Python内置函数 range(),通过指定初始值、终值、步长 来创建等差数列的一维数组,默认是不包括终值的

    linspace 代表线性等分向量的含义,通过指定初始值、终值、元素个数 来创建等差数列的一维数组,默认是包括终值的

     

    Array creation functions

    See the table below for a short list of standard array creation functions. Since NumPy is focused on numerical computing, the data type, if not specified, will in many cases be float64 (floating point).

    Reference

    Python for Data Analysis Second Edition

    https://www.runoob.com/python3/python3-func-range.html

  • 相关阅读:
    转载文章:用.NET开发MSN聊天机器人 MSN聊天机器人开发揭秘
    ppc全屏程序(转)
    表设计中遇到的多对多的关系解决方案 (zt)
    using ZedGraph
    DataTable.Select(expression)
    你认识它吗?什么是QR码?
    分享《Windows Mobile平台应用与开发》源代码
    收藏信息
    六世喇嘛仓央嘉措诗集
    使用Axis开发Web Service程序
  • 原文地址:https://www.cnblogs.com/agilestyle/p/12244066.html
Copyright © 2011-2022 走看看