numpy.pdf - NumPy Efficient Arrays and Numerical Computing for Python 1 18 Numerical Python Provides efficient storage and operations on dense data

numpy.pdf - NumPy Efficient Arrays and Numerical Computing...

This preview shows page 1 - 7 out of 18 pages.

NumPy Efficient Arrays and Numerical Computing for Python 1 / 18
Image of page 1
Numerical Python Provides efficient storage and operations on dense data buffers, i.e., arrays. I ndarray is the fundamental object I Vectorized operations on arrays I Broadcasting I File IO amd memory-mapped files In [1]: import numpy as np 2 / 18
Image of page 2
NumPy Array Element Types Arrays have elements of homogeneous data type In [2]: a = np.array([1, 2, 3.14]) In [3]: type(a) Out[3]: numpy.ndarray In [4]: a Out[4]: array([ 1. , 2. , 3.14]) In [5]: type(a[0]) Out[5]: numpy.float64 I Notice that the values were converted to floats. You can specify an explicit element type with the dtype keyword argument: In [6]: np.array(nums, dtype=’int’) Out[6]: array([1, 2, 3]) 3 / 18
Image of page 3
Out[10]: array([ 0., 0., 0., 0.])Create a multi-dimensional array of 1s with element typeint. Note thatfirst argument is a tuple of array dimensions. 4 / 18
Image of page 4
5 / 18
Image of page 5
NumPy Array Attributes Given: In [33]: a = np.array([[1,2,3], [4,5,6]]) In [34]: a Out[34]: array([[1, 2, 3], [4, 5, 6]]) ndim is the number of dimensions: In [37]: a.ndim Out[37]: 2 shape
Image of page 6
Image of page 7

You've reached the end of your free preview.

Want to read all 18 pages?

  • Fall '14
  • DaKuang
  • Array, 10%, NumPy, ndarray, Ndim, dtype

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture