array-to-latex: Turn a Numpy Array into Latex
Latex is used to write mathematical expressions. You can turn a Numpy array into latex using array-to-latex.
array-to-latex: Turn a Numpy Array into Latex Read More »
Latex is used to write mathematical expressions. You can turn a Numpy array into latex using array-to-latex.
array-to-latex: Turn a Numpy Array into Latex Read More »
Working with NumPy arrays that have units can be difficult, as it is not immediately clear what the units are, which can lead to errors.
The unyt package solves this by providing a subclass of NumPy’s ndarray class that knows units.
unyt arrays support standard NumPy array operations and functions while preserving the units associated with the data.
Link to unyt.
Favorite
unyt: Manipulate and Convert Units in NumPy Arrays Read More »
If you want to take elements from a NumPy array at specific indices, use numpy.take.
My previous tips on NumPy.
Favorite
NumPy.take: Take Elements From an Array Read More »
If you want to turn a pandas Series into a NumPy array, use Series.values.
My previous tips on pandas.
Favorite
Turn a pandas Series into a NumPy Array Read More »
If you try to check whether two arrays are equal, using an assert statement will give you an error. Use assert_array_equal instead.
assert_array_equal also shows you which elements are different between two arrays.
My previous tips on NumPy.
Favorite
Check if Two NumPy Arrays Are Equal Read More »
If one or more of your axes are of length one, you can remove those axes using numpy.squeeze.
Link to previous tips on NumPy.
Favorite
np.squeeze: Remove Axes of Length One From an Array Read More »
Sometimes, you might only want to check if two arrays are equal up to a certain precision. If so, use np.testing.assert_almost_equal.
The code above shows an example of this method.
Link to the source code. Favorite
If you want to get evenly spaced numbers over a specific interval, use np.linspace(start, stop, num).
The code above shows a use case of the np.linspace method.
Link to the source code. Favorite
NumPy.linspace: Get Evenly Spaced Numbers Over a Specific Interval Read More »
If you want to get elements of a Numpy array that are greater, smaller, or equal to a value or an array, simply use comparison operators such as <, <=, >, >=, ==.
The image above shows an example of using comparison operators.
Link to the source code.Favorite
Numpy Comparison Operators Read More »
If you want to test whether all elements along a given axis of a NumPy array evaluate to True, use np.all.
In the code above, I check if all elements are less than 3 in each column or row.
Link to the source code.Favorite
np.all: Test Whether All Elements along a Given Axis of a NumPy Array Evaluate to True Read More »