Member-only story
Here are 100 tips and tricks for using NumPy, a powerful library for numerical computing in Python:
Array Creation and Manipulation:
- Create an array:
numpy.array([1, 2, 3])
- Create a range:
numpy.arange(start, stop, step)
- Create evenly spaced values:
numpy.linspace(start, stop, num)
- Create an array filled with zeros:
numpy.zeros(shape)
- Create an array filled with ones:
numpy.ones(shape)
- Create an identity matrix:
numpy.eye(n)
- Reshape an array:
array.reshape(new_shape)
- Flatten an array:
array.flatten()
- Transpose an array:
array.T
- Concatenate arrays horizontally:
numpy.hstack((array1, array2))
- Concatenate arrays vertically:
numpy.vstack((array1, array2))
- Split an array:
numpy.split(array, indices_or_sections)
Array Indexing and Slicing:
- Access an element:
array[i]
- Slice an array:
array[start:stop:step]
- Access the last element:
array[-1]
- Access multiple elements:
array[[1, 3, 5]]