numpy basic 1 Flashcards
data type, array creation func (29 cards)
int8, uint8
i1, u1
int16, uint16,
i2, u2
int32, uint32
i4 , u4
int64, uint64
i8, u8
float16
f2
float32
f4 or f
float64
f8 or d
float128
f16 or g
complex64
c8 c16
complex128
c32
bool
?
object
0
string
S
unicode
U
array
Convert input data (list, tuple, array, or other sequence type) to an ndarray either by inferring a dtype
or explicitly specifying a dtype; copies the input data by default
In [19]: data1 = [6, 7.5, 8, 0, 1]
In [20]: arr1 = np.array(data1)
In [21]: arr1
Out[21]: array([ 6. , 7.5, 8. , 0. , 1. ])
asarray
Convert input to ndarray, but do not copy if the input is already an ndarray
no shit seen look into the future
arange Like the built-in range but returns an ndarray instead of a list
In [32]: np.arange(15) Out[32]: array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])
arange Like the built-in range but returns an ndarray instead of a list
In [32]: np.arange(15)
Out[32]: array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])
ones, zeros, empty ,full
quite the same hope u didn’t forget
ones_like, zeros_like, empty_like , full like
makes a arr full of value like the arr given as arg
np.astype
In [44]: numeric_strings = np.array([‘1.25’, ‘-9.6’, ‘42’], dtype=np.string_)
In [45]: numeric_strings.astype(float)
Out[45]: array([ 1.25, -9.6 , 42. ])
arr 1d index and slicing prblm
arr = np.arange(10)
arr[5:8] = ?
Out[63]: array([5, 6, 7])
arr2d = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
In [73]: arr2d[2]
= ?
Out[73]: array([7, 8, 9])
arr2d = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
In [74]: arr2d[0][2] and arr2d[0, 2]
output?
3