NumPy Foundation (i)

Source: Internet
Author: User

Install self-addressed

# #为什么使用NumPy

File vectorsumcompare.py

#!/usr/bin/env python# -*- coding:utf-8 -*-__author__ =  ' Teng ' import  Sysfrom datetime import datetimeimport numpy as npdef numpysum (n):     a = np.arange (n) **2    b = np.arange (n) **3     c = a+b    return cdef pythonsum (n):     a = range (n)     b = range (n)     c  = []    for i in range (Len (a)):         a[i] = i**2        b[i] = i**3         c.append (A[i]+ b[i])     return  Csize = int (Sys.argv[1]) Start = datetime.now () c = pythonsum (size) print  " Pythonsum: ",  cdelta = dateTime.now ()  - startprint  "The last 2 elements of the sum",  c[ -2:]print  "Pythonsum elapsed time in microseconds",  delta.microsecondsstart  = datetime.now () c = numpysum (size) print  "Numpysum:", cdelta =  DateTime.Now ()  - startprint  "The last 2 elements of the sum",  c[-2:]print  "Numpysum elapsed time in microseconds",  delta.microseconds

Run the above script like Python vectorsumcompare.py 10000

Advantages of NumPy

Simple

Fast speed when the data volume is large

# #NumPy数组对象

Debug method shape Returns the size of an element in a tuple tuple to each dimension of the NumPy array

Arange one-dimensional arrays

in [+]: M = Np.array ([Np.arange (2), Np.arange (2)])

in [+]: M

OUT[16]: Array ([[[0, 1],[0, 1]])

in [+]: M.shape

OUT[17]: (2, 2)

Ndarray is a multidimensional array object:

is divided into two parts of the actual data and the metadata that describes the data
















NumPy Foundation (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.