how do I calculate that an array of python numpy or me of all the calculate decimals and not skip like.
>> A = numpy.array ([[1,2,3], [4,5,6], [7,8,9]]).
>> C = numpy.array ([[7,8,9], [1,2,3], [4,5,6]]).
&开发者_如何学JAVAgt;> A / C
array ([[0, 0, 0],
[4, 2, 2],
[1, 1, 1]])
but in the first vector would not have to be given to absolute zero [0.143, 0.250, 0.333]
To avoid integer division, use numpy.true_divide(A,C)
. You can also put from __future__ import division
at the top of the file to default to this behavior.
Try converting one of the arrays A
or C
into an array of floats. For instance:
A = A * 1.0
Then the division will be floating point division.
Numpy arrays may have different types. You may also create a float array, it will always divide correctly:
>>> A = numpy.array ([[1,2,3], [4,5,6], [7,8,9]], dtype=float)
>>> A/2
array([[ 0.5, 1. , 1.5],
[ 2. , 2.5, 3. ],
[ 3.5, 4. , 4.5]])
Notice the dtype=
argument to numpy.array
精彩评论