w8 Flashcards
(27 cards)
whats numpy
fundamental package for scientific computing with python
Difference between arrays and lists
- All the elements in them are of the same type i.e all strings, all ints
- Arrays are multidimensional
Advantages of arrays
- Calculations using arrays are much faster than lists
- Very fast libraries for manipulating arrays
- Python provides convenient features for performing numerical calcs with arrays
Why calcs using arrays much faster than lists
Because data in an array is sequential in memory (in a block) - making it easy to access
This is contrasted to lists and tuples who have data located fragmentally and at various points in the computer library
what are one-dimensional arrays referred to as
vectors
what are two-dimensional arrays referred to as
matrices
when [:] is sliced, what does it actually slice
the whole thing
whats the general formula for 2-dimensional slicing
sliced_matrix = matrix[row_start:row_end, column_start:column_end]
Contiguous vs Non-contiguous set of data
contiguous data is where python gives us a view when sliced and any changes to the view will affect the original
non-contiguous data is where python just gives us a copy of the data
How are arrays added and subtracted
perfumed “element-wise”: elements of each array are matched up into their corresponding pairs and operation is performed on the pair
what happens if arrays of different lengths are added
will produce an error as they can’t be added
what are scalars
constants
how do scalars operate on arrays
perform the operation on each element separately
unsigned integers vs integers
unsigned integers stores only positive numbers and zero
integers store all numbers positive and negative
what does U10 mean? break it down
U indicates names are stored as “unicode strings”
10 signifies names won’t be longer than 10 characters
what does np.zeros do
creates a matrix of all zeroes
what does np.ones do
creates a matrix of all ones
what does np.eyes do
creates an identity matrix
what does np.arrange do
create a loop
what does np.linspance do
creates a number of values, evenly spaced from start to end
what does np.count_nonzero() do
counts how many elements in an array are non-zero
what does np.all do
a yes/no which tells is whether all records meet a specific condition
what does np.any do
a yes/no that tells us if there are any records that meet a certain condition
what does np.sum do
sum of entire array