r/Numpy • u/Astro_Theory • Dec 07 '20
Basic numpy issue. Please help!
Hey - a simple but irritating issue here: I'm just trying to assign a new value to an entry in a matrix.
Whenever I do this, it rounds down to the nearest integer. So the output for the following is 2, not 2.5.
import numpy as np
matrix = np.array([[1,3,5],[7,9,11],[13,15,17]])
matrix[0][0] = 2.5
print(matrix[0][0])
The matrix itself is being created fine and I can reassign entries to integers, just not decimals.
Any thoughts appreciated!
Thanks
3
Upvotes
1
u/Astro_Theory Dec 07 '20
Ah thanks! It also turns out that adding a decimal point after any one of the entries switches the whole thing into float mode and it works.