diodeBucks
diodeBucks

Reputation: 173

assign value to numpy arrary

I initialize

Tcoords = np.array([0,0])

and

Tcoords[0] =.1

but why when printing Tcoords still

Tcoords
array([0, 0])

Upvotes: 1

Views: 72

Answers (2)

LaPriWa
LaPriWa

Reputation: 1803

Use float instead of int. It will work:

Tcoords = np.array([0.0,0.0])

Upvotes: 1

Mike Müller
Mike Müller

Reputation: 85482

The assigned 0.1 will be cast into an integer. Use:

>>> Tcoords = np.array([0,0], dtype=np.float)
>>> Tcoords[0] = .1
>>> Tcoords
array([ 0.1,  0. ])

This is what happens:

>>>int(0.1)
0

Upvotes: 2

Related Questions