I want to binarize python list based on previous value, output should be 1 if previous value is lower, and 0 if higher. Example:
=ArrayFormula(QUERY(to_text({
Response!E2:H,Response!B2:D;
Response!I2:L,Response!B2:D;
Response!M2:P,Response!B2:D;
Response!Q2:T,Response!B2:D;
Response!U2:X,Response!B2:D;
Response!Z2:AC,Response!B2:D;
Response!AD2:AG,Response!B2:D;
Response!AH2:AK,Response!B2:D;
Response!AL2:AO,Response!B2:D;
Response!AP2:AS,Response!B2:D;
Response!AU2:AX,Response!B2:D;
Response!AY2:BB,Response!B2:D;
Response!BC2:BF,Response!B2:D;
Response!BG2:BJ,Response!B2:D;
Response!BK2:BN,Response!B2:D;
Response!BP2:BS,Response!B2:D;
Response!BT2:BW,Response!B2:D;
Response!BX2:CA,Response!B2:D;
Response!CB2:CE,Response!B2:D;
Response!CF2:CI,Response!B2:D;
Response!CK2:CN,Response!B2:D;
Response!CO2:CR,Response!B2:D;
Response!CS2:CV,Response!B2:D;
Response!CW2:CZ,Response!B2:D;
Response!DA2:DD,Response!B2:D}),"select * where Col1 <> '' Order By Col6"))
should become:
[18985.0, 20491.0, 18554.0, 14241.0, 13390.0, 14965.0,]
Is there any elegant way to do this? Thanks in advance!
答案 0 :(得分:2)
A list comprehension should work.
Set doc = ActiveDocument
strTemplate = "C:\Users\rajtilak\Desktop\Report.dotx"
Set docTemplate = Documents.Open(strTemplate)
Set hdr1 = docTemplate.Sections(1).headers(wdHeaderFooterPrimary)
Set hdr2 = doc.Sections(3).headers(wdHeaderFooterPrimary)
hdr1.Range.Copy
hdr2.Range.PasteAndFormat wdFormatOriginalFormatting
docTemplate.Close False
You might want to consider the case when two values are equal.
答案 1 :(得分:1)
You can use list comprehension along with hduser@slave3:/$ du -sh /hadoop-tmp/
2.8G /hadoop-tmp/
hduser@slave3:/$ hdfs dfs -du -s -h /
4.5 G /
function to achieve your desired result. I am hardcoding first value to be zip
since there is no previous value to compare
0
答案 2 :(得分:1)
ZonedDateTime zdt = ZonedDateTime.of( ld , lt , z ) ;
solution:
map
Output:
vals = [18985.0, 20491.0, 18554.0, 14241.0, 13390.0, 14965.0]
map(
lambda (ind, x):
1 if vals[ind] > vals[ind - 1] and ind != 0 else 0,
enumerate(vals)
)
答案 3 :(得分:0)
Numpy solution:
function local_pickup_extra_content_email($order, $is_admin_email) {
if ( $is_admin_email ) {
return;
}
if ( ICL_LANGUAGE_CODE == "he" && strpos( $order->get_shipping_method(), 'Local Pickup' ) !== false) {
echo '<p><strong>Note:</strong> Please wait for telephone confirmation of local pickup.</p>';
}
}
add_action( 'woocommerce_email_after_order_table', 'local_pickup_extra_content_email', 10, 2 );
The insert is needed to add a first element, which is always False. The array would be
import numpy as np
a=array([18985.0, 20491.0, 18554.0, 14241.0, 13390.0, 14965.0])
np.insert(a[1:]>a[:-1],0,False)
array([False, True, False, False, False, True], dtype=bool)
without it. If you want integers and not booleans (i.e. 0,1) use
array([True, False, False, False, True], dtype=bool)
Also you can shorten the above solutions with something like
np.insert(a[1:]>a[:-1],0,False).astype(int)
or even without the [0] + [int(i<j) for i,j in zip(l, l[1:])]
if you don't mind True and False (also int
->[0]
).
答案 4 :(得分:0)
Use <?php $colors_counter = 0; ?>
@foreach($posts as $post)
<div class="header-{{ ($colors_counter%2 == 0) ? 'blue' : 'red' : 'green' : 'yellow' }}">
{{ $post->name }}
</div>
<?php $colors_counter++; ?>
@endforeach
as an appropriate default value for the first comparison (it will never be inf
any number), and use use <
to create an appropriate iterator that starts at itertools.chain
then gives you the previous item in your data. This can be nice and concise with inf
and the map
module if you don't mind operator
objects as your result:
bool
This could be done with a list-comprehension using >>> from itertools import chain
>>> inf = float('inf')
>>> import operator as op
>>> list(map(op.lt, data, chain((inf,), data)))
[True, False, True, True, True, False]
as well, although, it starts to get clunky:
zip
But it allows for more convenient conversion to >>> [prev < curr for curr, prev in zip(data, chain((inf,), data))]
[False, True, False, False, False, True]
:
int