我有一个像这样的数组:
import matplotlib.pyplot as plt
def main(iterations,populationsize):
popde=generator(populationsize)
population=popde[0]
dead=popde[1]
plt.ion()
sc = plt.scatter([], []) # initialise empty scatter plot
for numit in range(iterations):
population=movement(population)
popde2=infection(population,populationsize,dead)
population=popde2[0]
dead=popde2[1]
populationsize=popde2[2]
plotter(population, sc) # pass scatter object to plotter function
plt.draw() # update the current figure
plt.pause(0.1)
def plotter(population, sc):
# create list of all x- and y-positions
posx = [people.positionx for people in population]
posy = [people.positiony for people in population]
# create list of colors
color = ['#88888']*len(population) # initialise all colors as grey
for ip, people in enumerate(population):
if people.status == 0:
color[ip] = 'b'
elif people.healthstatus == 0:
color[ip] = 'g'
elif people.healthstatus == 1:
color[ip] = 'y'
elif people.healthstatus == 2:
color[ip] = 'r'
# if none of these criteria match, the marker remains grey
sc.set_offsets(np.c_[posx, posy]) # update marker positions
sc.set_color(color) # update marker color
我想从数组中提取另一个数组,像这样:
array(10) { [0]=> array(21) { ["id"]=> string(3) "213" ["form_id"]=> string(2) "11" ["post_id"]=> NULL ["date_created"]=> string(19) "2020-04-20 15:50:16" ["date_updated"]=> string(19) "2020-04-20 15:50:16" ["is_starred"]=> string(1) "0" ["is_read"]=> string(1) "0" ["ip"]=> string(13) "188.211.58.78" ["source_url"]=> string(36) "https://www.torabi-md.ir/attendance/" ["user_agent"]=> string(129) "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.17763" ["currency"]=> string(3) "IRR" ["payment_status"]=> bool(false) ["payment_date"]=> NULL ["payment_amount"]=> NULL ["payment_method"]=> NULL ["transaction_id"]=> string(10) "3875200674" ["is_fulfilled"]=> NULL ["created_by"]=> NULL ["transaction_type"]=> NULL ["status"]=> string(6) "active" [1]=> string(8) "ورود" } [1]=> array(21) { ["id"]=> string(3) "214" ["form_id"]=> string(2) "11" ["post_id"]=> NULL ["date_created"]=> string(19) "2020-04-20 16:08:40" ["date_updated"]=> string(19) "2020-04-20 16:08:40" ["is_starred"]=> string(1) "0" ["is_read"]=> string(1) "0" ["ip"]=> string(13) "188.211.58.78" ["source_url"]=> string(36) "https://www.torabi-md.ir/attendance/" ["user_agent"]=> string(129) "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.17763" ["currency"]=> string(3) "IRR" ["payment_status"]=> bool(false) ["payment_date"]=> NULL ["payment_amount"]=> NULL ["payment_method"]=> NULL ["transaction_id"]=> string(10) "8137836043" ["is_fulfilled"]=> NULL ["created_by"]=> NULL ["transaction_type"]=> NULL ["status"]=> string(6) "active" [1]=> string(8) "خروج" } [2]=> array(21) { ["id"]=> string(3) "215" ["form_id"]=> string(2) "11" ["post_id"]=> NULL ["date_created"]=> string(19) "2020-04-21 11:35:02" ["date_updated"]=> string(19) "2020-04-21 11:35:02" ["is_starred"]=> string(1) "0" ["is_read"]=> string(1) "0" ["ip"]=> string(13) "188.211.58.78" ["source_url"]=> string(36) "https://www.torabi-md.ir/attendance/" ["user_agent"]=> string(129) "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.17763" ["currency"]=> string(3) "IRR" ["payment_status"]=> bool(false) ["payment_date"]=> NULL ["payment_amount"]=> NULL ["payment_method"]=> NULL ["transaction_id"]=> string(10) "5580962715" ["is_fulfilled"]=> NULL ["created_by"]=> NULL ["transaction_type"]=> NULL ["status"]=> string(6) "active" [1]=> string(8) "ورود" } [3]=> array(21) { ["id"]=> string(3) "216" ["form_id"]=> string(2) "11" ["post_id"]=> NULL ["date_created"]=> string(19) "2020-04-21 16:27:10" ["date_updated"]=> string(19) "2020-04-21 16:27:10" ["is_starred"]=> string(1) "0" ["is_read"]=> string(1) "0" ["ip"]=> string(13) "188.211.58.78" ["source_url"]=> string(36) "https://www.torabi-md.ir/attendance/" ["user_agent"]=> string(129) "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.17763" ["currency"]=> string(3) "IRR" ["payment_status"]=> bool(false) ["payment_date"]=> NULL ["payment_amount"]=> NULL ["payment_method"]=> NULL ["transaction_id"]=> string(10) "7161122321" ["is_fulfilled"]=> NULL ["created_by"]=> NULL ["transaction_type"]=> NULL ["status"]=> string(6) "active" [1]=> string(8) "خروج" } [4]=> array(21) { ["id"]=> string(3) "217" ["form_id"]=> string(2) "11" ["post_id"]=> NULL ["date_created"]=> string(19) "2020-04-22 11:38:14" ["date_updated"]=> string(19) "2020-04-22 11:38:14" ["is_starred"]=> string(1) "0" ["is_read"]=> string(1) "0" ["ip"]=> string(14) "188.211.42.159" ["source_url"]=> string(36) "https://www.torabi-md.ir/attendance/" ["user_agent"]=> string(129) "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.17763" ["currency"]=> string(3) "IRR" ["payment_status"]=> bool(false) ["payment_date"]=> NULL ["payment_amount"]=> NULL ["payment_method"]=> NULL ["transaction_id"]=> string(10) "3069574022" ["is_fulfilled"]=> NULL ["created_by"]=> NULL ["transaction_type"]=> NULL ["status"]=> string(6) "active" [1]=> string(8) "ورود" } [5]=> array(21) { ["id"]=> string(3) "218" ["form_id"]=> string(2) "11" ["post_id"]=> NULL ["date_created"]=> string(19) "2020-04-22 16:22:25" ["date_updated"]=> string(19) "2020-04-22 16:22:25" ["is_starred"]=> string(1) "0" ["is_read"]=> string(1) "0" ["ip"]=> string(14) "188.211.42.159" ["source_url"]=> string(36) "https://www.torabi-md.ir/attendance/" ["user_agent"]=> string(129) "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.17763" ["currency"]=> string(3) "IRR" ["payment_status"]=> bool(false) ["payment_date"]=> NULL ["payment_amount"]=> NULL ["payment_method"]=> NULL ["transaction_id"]=> string(10) "4201845766" ["is_fulfilled"]=> NULL ["created_by"]=> NULL ["transaction_type"]=> NULL ["status"]=> string(6) "active" [1]=> string(8) "خروج" } [6]=> array(21) { ["id"]=> string(3) "219" ["form_id"]=> string(2) "11" ["post_id"]=> NULL ["date_created"]=> string(19) "2020-04-25 11:30:12" ["date_updated"]=> string(19) "2020-04-25 11:30:12" ["is_starred"]=> string(1) "0" ["is_read"]=> string(1) "0" ["ip"]=> string(14) "188.211.42.159" ["source_url"]=> string(36) "https://www.torabi-md.ir/attendance/" ["user_agent"]=> string(129) "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.17763" ["currency"]=> string(3) "IRR" ["payment_status"]=> bool(false) ["payment_date"]=> NULL ["payment_amount"]=> NULL ["payment_method"]=> NULL ["transaction_id"]=> string(10) "4789618480" ["is_fulfilled"]=> NULL ["created_by"]=> NULL ["transaction_type"]=> NULL ["status"]=> string(6) "active" [1]=> string(8) "ورود" } [7]=> array(21) { ["id"]=> string(3) "220" ["form_id"]=> string(2) "11" ["post_id"]=> NULL ["date_created"]=> string(19) "2020-04-26 11:28:03" ["date_updated"]=> string(19) "2020-04-26 11:28:03" ["is_starred"]=> string(1) "0" ["is_read"]=> string(1) "0" ["ip"]=> string(13) "5.238.225.138" ["source_url"]=> string(36) "https://www.torabi-md.ir/attendance/" ["user_agent"]=> string(129) "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.17763" ["currency"]=> string(3) "IRR" ["payment_status"]=> bool(false) ["payment_date"]=> NULL ["payment_amount"]=> NULL ["payment_method"]=> NULL ["transaction_id"]=> string(10) "0141411521" ["is_fulfilled"]=> NULL ["created_by"]=> NULL ["transaction_type"]=> NULL ["status"]=> string(6) "active" [1]=> string(8) "ورود" } [8]=> array(21) { ["id"]=> string(3) "221" ["form_id"]=> string(2) "11" ["post_id"]=> NULL ["date_created"]=> string(19) "2020-04-26 16:30:07" ["date_updated"]=> string(19) "2020-04-26 16:30:07" ["is_starred"]=> string(1) "0" ["is_read"]=> string(1) "0" ["ip"]=> string(13) "5.238.225.138" ["source_url"]=> string(36) "https://www.torabi-md.ir/attendance/" ["user_agent"]=> string(129) "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.17763" ["currency"]=> string(3) "IRR" ["payment_status"]=> bool(false) ["payment_date"]=> NULL ["payment_amount"]=> NULL ["payment_method"]=> NULL ["transaction_id"]=> string(10) "5123886653" ["is_fulfilled"]=> NULL ["created_by"]=> NULL ["transaction_type"]=> NULL ["status"]=> string(6) "active" [1]=> string(8) "خروج" } [9]=> array(21) { ["id"]=> string(3) "222" ["form_id"]=> string(2) "11" ["post_id"]=> NULL ["date_created"]=> string(19) "2020-04-27 11:44:57" ["date_updated"]=> string(19) "2020-04-27 11:44:57" ["is_starred"]=> string(1) "0" ["is_read"]=> string(1) "0" ["ip"]=> string(13) "5.238.254.231" ["source_url"]=> string(36) "https://www.torabi-md.ir/attendance/" ["user_agent"]=> string(129) "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.17763" ["currency"]=> string(3) "IRR" ["payment_status"]=> bool(false) ["payment_date"]=> NULL ["payment_amount"]=> NULL ["payment_method"]=> NULL ["transaction_id"]=> string(10) "9130531791" ["is_fulfilled"]=> NULL ["created_by"]=> NULL ["transaction_type"]=> NULL ["status"]=> string(6) "active" [1]=> string(8) "ورود" } }
我已经在具有重力形式API的wordpress中尝试了以下代码:
Array ( [0] => Array ( [2020-04-20] => Array ( [0] => 15:50:16 [1] => 16:08:40) ) ..... )
运行代码后,我得到以下结果:
$new_array = array();
$search_criteria = array(
'status' => 'active'
);
$sorting = array( 'key' => 'date_updated', 'direction' => 'ASC' );
$entries = GFAPI::get_entries( 11,$search_criteria,$sorting);
var_dump ($entries);
echo "<hr>";
foreach ($entries as $entry) {
if ($entry [1]=="ورود"){
$date = explode (" ", $entry ["date_updated"]) [0];
$start_time = explode (" ", $entry ["date_updated"]) [1];
//echo $date."===>".$time."<br>";
array_push($new_array,array($date => array ($start_time,"empty")));
}
}
$x="0";
foreach ($entries as $entry) {
if ($entry [1]=="خروج"){
$date = explode (" ", $entry ["date_updated"]) [0];
$end_time = explode (" ", $entry ["date_updated"]) [1];
$new_array [$x][$date][1] = $end_time;
$x=$x+1;
}
}
print_r($new_array);
当我的原始数组中缺少值时,我的代码当前不起作用。 注意[2020-04-25]:没有خروج记录。这是正确的。但是之后我得到了错误的结果。