Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

Python Programming/numpy

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

Database Programming Game Programming in Python Numpy is a numeric library for Python. Its main purpose is to provide fast manipulation of multidimensional arrays. Installation It's provided with the main Linux distribution, however it can be installed through the Debian package python-numpy. On systems with pip, running pip install numpy will work. On Windows, it can be downloaded on http://sourceforge.net/projects/numpy/files/. Then, once the .zip unpacked, the installation is done by entering into the console: python setup.py install In case of error: ImportError “No Module named Setuptools”, save the file https://bootstrap.pypa.io/ez_setup.py into the Python folder, and install it with: python ez_setup.py install. Microsoft Visual C++ 9.0 is required, download it on https://www.microsoft.com/en-us/download/details.aspx?id=44266 Arrays Arrays in numpy are of type numpy.ndarray. However, the most common way of defining them is using numpy.array, which is a function. For example, import numpy a = numpy.array([1, 2, 3]) b = numpy.array([[3, 1, 4, 1, 5], [9, 2, 6, 5, 3]]) There are other ways to initialize numpy arrays. For example, to initialize a random array, import numpy rng = numpy.random.default_rng() # initialize random number generator a = rng.random(5) # five random floats between 0 and 1 b = rng.random(3, 5) # a 3 by 5 array of floats between 0 and 1 c = rng.integers(0, 10, size=3) # 3 random integers between 0 and 10, excluding 10 and including 0Some other ways of initialization are:import numpy a = numpy.zeros(2, 3) # 2 by 3 array of only zeros. b = numpy.ones(3, 5) # 3 by 5 array of only ones. Histogram import numpy mydata = [numpy.random.normal(0,1) for i in range(10000) ] h, n = numpy.histogram( mydata , 100, (-5,5) ) See also http://numpy.scipy.org/ http://docs.scipy.org/doc/numpy/reference/ Research using FOSS Database Programming Game Programming in Python