Python Forum
numpy subtraction of two arrays
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
numpy subtraction of two arrays
#2
Firstly, you can directly subtract numpy arrays; no need for numpy.subtract.

Secondly, this is probably just a display issue. -2*10**-16 is basically zero with some added floating point imprecision.

Try adding this line before you print the array:
np.set_printoptions(suppress=True)
Not sure why you are getting this behavior by default though.

My results:
import numpy as np


a= [[ 1.0, 0.85979163, 0.0, 0.11766047, 0.19353699],
    [ 0.8589698, 1.0, 0.24111901, 0.0, 0.0 ],
    [ 0., 0.24554123, 1.0, 0.09234979, 0.07125199],
    [ 0.31269982, 0.22558714, 0.29298401, 1.0, 0.475543 ],
    [ 0.18880995, 0.0, 0.06580817, 0.32276821, 1.0 ]]

b = np.ones((5,5), dtype=int)

print(b - a)
Output:
[[0. 0.14020837 1. 0.88233953 0.80646301] [0.1410302 0. 0.75888099 1. 1. ] [1. 0.75445877 0. 0.90765021 0.92874801] [0.68730018 0.77441286 0.70701599 0. 0.524457 ] [0.81119005 1. 0.93419183 0.67723179 0. ]]
Reply


Messages In This Thread
numpy subtraction of two arrays - by devenuro - Sep-24-2018, 12:30 AM
RE: numpy subtraction of two arrays - by Mekire - Sep-24-2018, 12:55 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Numpy] How to store different data type in one numpy array? water 7 299 Mar-26-2024, 02:18 PM
Last Post: snippsat
  Pandas dataframes and numpy arrays bytecrunch 1 1,292 Oct-11-2022, 08:08 PM
Last Post: Larz60+
  Numpy returns "TypeError: unsupported operand type(s) for *: 'numpy.ufunc' and 'int'" kalle 2 2,530 Jul-19-2022, 06:31 AM
Last Post: paul18fr
  comparing floating point arrays to arrays of integers in Numpy amjass12 0 1,613 Jul-26-2021, 11:58 AM
Last Post: amjass12
  list subtraction d8a988 3 2,118 Oct-23-2020, 04:49 PM
Last Post: Gribouillis
  Corrupted numpy arrays when save to file. DreamingInsanity 2 3,187 Dec-14-2019, 12:12 PM
Last Post: DreamingInsanity
  Numpy arrays and compatability with Fortran arrays merrittr 0 1,850 Sep-03-2019, 03:54 AM
Last Post: merrittr
  Converting set of tuples to set of 2D numpy arrays ThemePark 0 2,569 Aug-04-2019, 05:07 PM
Last Post: ThemePark
  "erlarge" a numpy-matrix to numpy-array PhysChem 2 2,932 Apr-09-2019, 04:54 PM
Last Post: PhysChem
  How to do matrix subtraction SriRajesh 0 2,690 Jun-01-2018, 02:00 PM
Last Post: SriRajesh

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020