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

• 17

This preview shows page 1 - 4 out of 17 pages.

NumPy Efficient Arrays and Numerical Computing for Python 1 / 17

Subscribe to view the full document.

Numerical Python Provides efficient storage and operations on dense data buffers, i.e., arrays. I ndarray is the fundamental object I Vectorized (no loop) operations on arrays I Broadcasting I File IO amd memory-mapped files In [1]: import numpy as np 2 / 17
NumPy Array Element Types Arrays have elements of homogeneous data type In [2]: nums = [1, 2, 3.14] In [3]: nums Out[3]: [1, 2, 3.14] In [4]: np.array(nums) Out[4]: array([ 1. , 2. , 3.14]) In [5]: type(Out[4][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 / 17

Subscribe to view the full document.

Basic Array Creation Pass list to np.array() (nested lists create multi-dimensional arrays) In [9]: np.array([[1,2,3],[4,5,6]]) Out[9]: array([[1, 2, 3], [4, 5, 6]]) Create a one-dimensional array of zeros, dtype defaults to float : In [10]: np.zeros(4) Out[10]: array([ 0., 0., 0., 0.]) Create a multi-dimensional array of 1s with element type int . Note that first argument is a tuple of array dimensions. In [11]: np.ones((2, 3), dtype=int)

#### You've reached the end of your free preview.

Want to read all 17 pages?

• Spring '12
• summet

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern