-1
我有一個非常大的numpy數組,Python中充滿了氣象數據。爲了觀察有缺陷的數據,我想查看每個值並測試它是否小於-1。最終我想用0和1的邏輯數組來表示這個值,其中1表示指數,其值小於-1,零代表所有其他指數。我已經使用numpy.where funtion如下從numpy陣列創建邏輯陣列
logarr = np.where(metdat < -1)
它返回原來的陣列和零的,用於當該條件爲真陣列(約200倍),嘗試。我已經使用Sci.Py.org奠定了numpy.where語法,其中
logarr = np.where(metdat < -1 [1,0])
,但我不喜歡的程序的語法嘗試。我做錯了什麼,或者有人會推薦一個更好的方法來解決這個問題?
感謝, jmatt
你錯位了括號。嘗試:'np.where(metdat <-1)[1] [0]' – shx2
或此版本.... a = np.array([0,-2,1,1,0,-2,0] )使用... np.where(a <-1,1,0)得到.... array([0,1,0,0,0,1,0]) –