title-img


Zeros and Ones python

zeros The zeros tool returns a new array with a given shape and type filled with 's. import numpy print numpy.zeros((1,2)) #Default type is float #Output : [[ 0. 0.]] print numpy.zeros((1,2), dtype = numpy.int) #Type changes to int #Output : [[0 0]] ones The ones tool returns a new array with a given shape and type filled with 's. import numpy print numpy.ones((1,2)) #Default type is float #Output : [[ 1. 1.]] print numpy.ones

View Solution →

Array Mathematics Python

Basic mathematical functions operate element-wise on arrays. They are available both as operator overloads and as functions in the NumPy module. import numpy a = numpy.array([1,2,3,4], float) b = numpy.array([5,6,7,8], float) print a + b #[ 6. 8. 10. 12.] print numpy.add(a, b) #[ 6. 8. 10. 12.] print a - b #[-4. -4. -4. -4.] print numpy.subtract(a, b) #[-4. -4. -4. -4.] print a * b #[ 5. 12.

View Solution →

Floor, Ceil and Rint python

floor The tool floor returns the floor of the input element-wise. The floor of x is the largest integer i where i<=x. import numpy my_array = numpy.array([1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9]) print numpy.floor(my_array) #[ 1. 2. 3. 4. 5. 6. 7. 8. 9.] ceil The tool ceil returns the ceiling of the input element-wise. The ceiling of x is the smallest integer i where i<=x. import numpy my_array = numpy.array([1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9]

View Solution →

Sum and Prod python

sum The sum tool returns the sum of array elements over a given axis. import numpy my_array = numpy.array([ [1, 2], [3, 4] ]) print numpy.sum(my_array, axis = 0) #Output : [4 6] print numpy.sum(my_array, axis = 1) #Output : [3 7] print numpy.sum(my_array, axis = None) #Output : 10 print numpy.sum(my_array) #Output : 10 By default, the axis value is None. Therefore, it performs a sum over all the dimensions of the input array. prod Th

View Solution →

Min and Max python

min The tool min returns the minimum value along a given axis. import numpy my_array = numpy.array([[2, 5], [3, 7], [1, 3], [4, 0]]) print numpy.min(my_array, axis = 0) #Output : [1 0] print numpy.min(my_array, axis = 1) #Output : [2 3 1 0] print numpy.min(my_array, axis = None) #Output : 0 print numpy.min(my_array) #Output : 0 By default, the axis value is None. The

View Solution →