Python 3.x Numpy数组和不同值的比较

Python 3.x Numpy数组和不同值的比较,python-3.x,csv,numpy,numpy-ndarray,Python 3.x,Csv,Numpy,Numpy Ndarray,出于再现性的原因,我正在共享数据 从第2列中,我想读取当前行并将其与前一行的值进行比较。如果它更大,我会继续比较。如果当前值小于上一行的值,我想将当前值(较小)除以上一行的值(较大)。因此,以下代码: import numpy as np import matplotlib.pyplot as plt protocols = {} types = {"data_c": "data_c.csv", "data_r": "data_r.csv", "data_v": "data_v.csv"}

出于再现性的原因,我正在共享数据

从第2列中,我想读取当前行并将其与前一行的值进行比较。如果它更大,我会继续比较。如果当前值小于上一行的值,我想将当前值(较小)除以上一行的值(较大)。因此,以下代码:

import numpy as np
import matplotlib.pyplot as plt

protocols = {}

types = {"data_c": "data_c.csv", "data_r": "data_r.csv", "data_v": "data_v.csv"}

for protname, fname in types.items():
    col_time,col_window = np.loadtxt(fname,delimiter=',').T
    trailing_window = col_window[:-1] # "past" values at a given index
    leading_window  = col_window[1:]  # "current values at a given index
    decreasing_inds = np.where(leading_window < trailing_window)[0]
    quotient = leading_window[decreasing_inds]/trailing_window[decreasing_inds]
    quotient_times = col_time[decreasing_inds]

    protocols[protname] = {
        "col_time": col_time,
        "col_window": col_window,
        "quotient_times": quotient_times,
        "quotient": quotient,
    }

这非常适用于值分别为0.7和0.5的
data\u c
data\u r
。这意味着它仅在
值唯一(或固定)时工作。但是,当
值大于1时,它不起作用。例如,
data_m
的商值介于0.65和0.7之间(即
0.65如果始终具有唯一商,并且始终具有唯一商边界,则我建议如下:

ud_m_bounds = np.r_[0.65,0.7]

uq = unique_quotient
uq_min,uq_max = uq.min(),uq.max()

def is_uq_bounded_by(unique_data_bounds):
  ud_min,ud_max = unique_data_bounds.min(), unique_data_bounds.max()
  left_bounded  = ud_min <= uq_min <= ud_max
  right_bounded = ud_min <= uq_max <= ud_max
  bounded = left_bounded & right_bounded
  return bounded

label = 'ERROR -- DATA UNCLASSIFIED'
if len(uq) > 2:
  if is_uq_bounded_by( unique_data_m_bounds ):
    label = 'data_m'
elif 0 < len(uq) <= 2:
  if np.array_equal( uq, unique_data_v_quotient):
    label = 'data_v' 
  if np.array_equal( uq, unique_data_c_quotient):
    label = 'data_c'
  elif np.array_equal( uq, unique_data_r_quotient):
    label = 'data_r'
print(label)
ud_m_bounds=np.r_[0.65,0.7]
uq=唯一商
uq_min,uq_max=uq.min(),uq.max()
def受以下条件限制(唯一数据限制):
ud_min,ud_max=unique_data_bounds.min(),unique_data_bounds.max()

left_bounded=ud_min如果你始终有唯一的商,并且始终有唯一的商边界,那么我建议如下:

ud_m_bounds = np.r_[0.65,0.7]

uq = unique_quotient
uq_min,uq_max = uq.min(),uq.max()

def is_uq_bounded_by(unique_data_bounds):
  ud_min,ud_max = unique_data_bounds.min(), unique_data_bounds.max()
  left_bounded  = ud_min <= uq_min <= ud_max
  right_bounded = ud_min <= uq_max <= ud_max
  bounded = left_bounded & right_bounded
  return bounded

label = 'ERROR -- DATA UNCLASSIFIED'
if len(uq) > 2:
  if is_uq_bounded_by( unique_data_m_bounds ):
    label = 'data_m'
elif 0 < len(uq) <= 2:
  if np.array_equal( uq, unique_data_v_quotient):
    label = 'data_v' 
  if np.array_equal( uq, unique_data_c_quotient):
    label = 'data_c'
  elif np.array_equal( uq, unique_data_r_quotient):
    label = 'data_r'
print(label)
ud_m_bounds=np.r_[0.65,0.7]
uq=唯一商
uq_min,uq_max=uq.min(),uq.max()
def受以下条件限制(唯一数据限制):
ud_min,ud_max=unique_data_bounds.min(),unique_data_bounds.max()
左边界=ud最小值