简体   繁体   English

如何在Python中的另一个numy数组中保存一个numpy数组

[英]How to save a numpy array in another numy array in python

I need to save a numpy array in a given location of another numpy array 我需要将一个numpy数组保存在另一个numpy数组的给定位置中

import numpy as np
spotsAreaArray=np.zeros(30)
weatherConditions=np.zeros(30)

def saveInitialSpotId(spotId,spotArea,humidityReading,temperatureReading,lightReading):
    #Store initial area of the spot at the respective location of the spot id
    if spotsAreaArray[spotId] == 0:
        spotsAreaArray[spotId]=spotArea
        if weatherConditions[spotId] == 0:
            sensorReadings=np.array(humidityReading,temperatureReading,lightReading)
            weatherConditions[spotId]=sensorReadings
            print(weatherConditions)
    print(spotsAreaArray)

saveInitialSpotId(0,23,33,33,33)
saveInitialSpotId(0,25,55,55,55)
saveInitialSpotId(1,24,44,44,44)
saveInitialSpotId(1,99,99,99,99)

what I need to do is to,store the sensorReadings array values in given spotId location in weatherConditions array.But this isn't working.Please give me a guidance to achieve this? 我需要做的是将sensorReadings数组值存储在weatherConditions数组中给定的spotId位置。但这不起作用。请给我指导以实现此目的?

np.array does not take 3 positional arguments. np.array不接受3个位置参数。 Making your readings a single list instead of a series of arguments will solve the issue. 将您的读数作为一个列表而不是一系列参数将解决此问题。

sensorReadings=np.array([humidityReading,temperatureReading,lightReading])

And just to be on the safe side: your array initialization will also yield trouble, as you will run into: 出于安全考虑:数组初始化也会产生麻烦,因为您会遇到以下问题:

ValueError: setting an array element with a sequence. ValueError:使用序列设置数组元素。

Which can, for example, be solved by initializing your array as: 例如,可以通过将数组初始化为:

weatherConditions=np.zeros((30,3))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM