In [1]:
test = "Hello World"
In [2]:
print ("test: " + test)
NumPy is the fundamental package for scientific computing with Python. It contains among other things:
Besides its obvious scientific uses, NumPy can also be used as an efficient multi-dimensional container of generic data. Arbitrary data-types can be defined. This allows NumPy to seamlessly and speedily integrate with a wide variety of databases.
Library documentation: http://www.numpy.org/
NumPy’s main object is the homogeneous multidimensional array. It is a table of elements (usually numbers), all of the same type, indexed by a tuple of positive integers. In NumPy dimensions are called axes. The number of axes is rank.
For example, the coordinates of a point in 3D space [1, 2, 1] is an array of rank 1, because it has one axis. That axis has a length of 3. In the example pictured below, the array has rank 2 (it is 2-dimensional). The first dimension (axis) has a length of 2, the second dimension has a length of 3.
NumPy’s array class is called ndarray. It is also known by the alias array. Note that numpy.array is not the same as the Standard Python Library class array.array, which only handles one-dimensional arrays and offers less functionality. The more important attributes of an ndarray object are:
In [ ]:
#
In [3]:
#The function zeros creates an array full of zeros
In [4]:
# function ones creates an array full of ones
In [5]:
#function empty creates an array whose initial content is random and depends on the state of the memory
In [6]:
# To create sequences of numbers, NumPy provides a function analogous to range that returns arrays instead of lists.
When arange is used with floating point arguments, it is generally not possible to predict the number of elements obtained, due to the finite floating point precision. For this reason, it is usually better to use the function linspace that receives as an argument the number of elements that we want,instead of the step
a1 = np.random.random((2,3))
print(a1) a1+=3 print(a1)
b1 = np.random.rand(2,3) *100
print(b1)
c1 = np.random.randint(0,5,size=(2,3))
print(c1)
r1 = np.random.randn(500)
When you print an array, NumPy displays it in a similar way to nested lists, but with the following layout:
One-dimensional arrays can be indexed, sliced and iterated over, much like lists and other Python sequences.
The dots (...) represent as many colons as needed to produce a complete indexing tuple. For example, if x is a rank 5 array (i.e., it has 5 axes), then
In [ ]: