Home > database >  go through two np.arrays and delete all values bigger then a defined value in one array
go through two np.arrays and delete all values bigger then a defined value in one array

Time:10-16

I got the arrays a and b of the same length. If I go ascending through both arrays parallely, I want to delete every value in both arrays for the every value in array a > 0.2.

print(a)
[0.01898843 0.02292621 0.02621628 0.02949512 0.03256304 0.03648436
  0.04372925 0.04113532 0.05106076 0.052512   0.04578903 0.05662923
  0.05624261 0.0626851  0.06491405 0.06835764 0.07395112 0.075808
  0.09126322 0.1168302  0.12331931 0.11512589 0.13179135 0.13810872
  0.14401422 0.14512059 0.15058154 0.1600896  0.15490434 0.16916868
  0.15755018 0.16333916 0.17718988 0.16769979 0.18357823 0.17304274
  0.18715775 0.19745513 0.19012131 0.20743668 0.20991725 0.22387453
  0.22907572 0.23116967 0.25244596 0.2550046  0.25958188]]
print(b)
[0.24469897 0.45153278 0.4513381  0.46295688 0.7054203  0.68534905
 0.24309576 0.92957395 0.25478074 0.23484863 0.68354946 0.26241717
 0.5774168  0.22709402 0.6631634  0.41246122 0.4266638  0.5739711
 0.20643993 0.58073324 0.46782446 1.1465902  0.5842695  0.5990051
 0.4022772  0.9816252  1.0006629  0.25262806 0.61737466 0.2234575
 1.0764375  0.7229736  0.22833306 0.967518   0.25310978 1.5422901
 0.6496138  0.25886557 1.2906564  0.46001527 0.65197116 0.41509193
 0.6179607  0.57257795 0.22474702 0.22528468 0.24215169]

Afterwards a and b should be:

a
[0.01898843 0.02292621 0.02621628 0.02949512 0.03256304 0.03648436
  0.04372925 0.04113532 0.05106076 0.052512   0.04578903 0.05662923
  0.05624261 0.0626851  0.06491405 0.06835764 0.07395112 0.075808
  0.09126322 0.1168302  0.12331931 0.11512589 0.13179135 0.13810872
  0.14401422 0.14512059 0.15058154 0.1600896  0.15490434 0.16916868
  0.15755018 0.16333916 0.17718988 0.16769979 0.18357823 0.17304274
  0.18715775 0.19745513 0.19012131]]

b
[0.24469897 0.45153278 0.4513381  0.46295688 0.7054203  0.68534905
 0.24309576 0.92957395 0.25478074 0.23484863 0.68354946 0.26241717
 0.5774168  0.22709402 0.6631634  0.41246122 0.4266638  0.5739711
 0.20643993 0.58073324 0.46782446 1.1465902  0.5842695  0.5990051
 0.4022772  0.9816252  1.0006629  0.25262806 0.61737466 0.2234575
 1.0764375  0.7229736  0.22833306 0.967518   0.25310978 1.5422901
 0.6496138  0.25886557 1.2906564]

CodePudding user response:

You can do:

mask = a <= 0.2
a,b = a[mask], b[mask]
  • Related