numpy

Solutions on MaxInterview for numpy by the best coders in the world

showing results for - "numpy"
Lucas
24 Feb 2016
1>>> import numpy as np
2>>> a = np.array([2,3,4])
3>>> a
4array([2, 3, 4])
5>>> a.dtype
6dtype('int64')
7>>> b = np.array([1.2, 3.5, 5.1])
8>>> b.dtype
9dtype('float64')
10
Oskar
26 Jan 2017
1def quicksort(arr):
2    if len(arr) <= 1:
3        return arr
4    pivot = arr[len(arr) // 2]
5    left = [x for x in arr if x < pivot]
6    middle = [x for x in arr if x == pivot]
7    right = [x for x in arr if x > pivot]
8    return quicksort(left) + middle + quicksort(right)
9
10print(quicksort([3,6,8,10,1,2,1]))
11# Prints "[1, 1, 2, 3, 6, 8, 10]"
12
Riccardo
30 Sep 2020
1x = 3
2print(type(x)) # Prints "<class 'int'>"
3print(x)       # Prints "3"
4print(x + 1)   # Addition; prints "4"
5print(x - 1)   # Subtraction; prints "2"
6print(x * 2)   # Multiplication; prints "6"
7print(x ** 2)  # Exponentiation; prints "9"
8x += 1
9print(x)  # Prints "4"
10x *= 2
11print(x)  # Prints "8"
12y = 2.5
13print(type(y)) # Prints "<class 'float'>"
14print(y, y + 1, y * 2, y ** 2) # Prints "2.5 3.5 5.0 6.25"
15
Mika
23 Mar 2016
1t = True
2f = False
3print(type(t)) # Prints "<class 'bool'>"
4print(t and f) # Logical AND; prints "False"
5print(t or f)  # Logical OR; prints "True"
6print(not t)   # Logical NOT; prints "False"
7print(t != f)  # Logical XOR; prints "True"
8