each

Output each combination of an array of numbers with javascript

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have several numbers in an array var numArr = [1, 3, 5, 9]; I want to cycle through that array and multiply every unique 3 number combination as follows: 1 * 3 * 5 = 1 * 3 * 9 = 1 * 5 * 9 = 3 * 5 * 9 = Then return an array of all the calculations var ansArr = [15,27,45,135]; Anyone have an elegant solution? Thanks in advance. 回答1: A general-purpose algorithm for generating combinations is as follows: function combinations(numArr, choose, callback) { var n = numArr.length; var c = []; var inner = function(start, choose_) { if (choose_ == 0)

LISP: Find occurrences of each word in a sentence.

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Can someone please explain to me how I search for the occurrences of each word in a sentence, such as "the cat sat on the mat" in Common lisp ? The user has to have inputted this line of text before hand and then the occurrences must be counted from that. Any help on even where to start would help. 回答1: Have a look at split-by-one-space in The Common Lisp Cookbook (defun split-by-one-space (string) "Returns a list of substrings of string divided by ONE space each. Note: Two consecutive spaces will be seen as if there were an empty string

Estimating an area of an image generated by a set of points (Alpha shapes??)

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a set of points in an example ASCII file showing a 2D image. I would like to estimate the total area that these points are filling. There are some places inside this plane that are not filled by any point because these regions have been masked out. What I guess might be practical for estimating the area would be applying a concave hull or alpha shapes . I tried this approach to find an appropriate alpha value, and consequently estimate the area. from shapely.ops import cascaded_union, polygonize import shapely.geometry as geometry

wide to long multiple measures each time

匿名 (未验证) 提交于 2019-12-03 01:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I know the wide to long has been asked way too many times on here but I can't figure out how to turn the following into long format. Shoot I even asked one of the wide to long with 2 repeated measures on SO. I'm becoming frustrated with my inability to convert my data. How can I turn this (variable order doesn't matter): id trt work.T1 play.T1 talk.T1 total.T1 work.T2 play.T2 talk.T2 total.T2 1 x1.1 cnt 0.34434350 0.7841665 0.1079332 0.88803151 0.64836951 0.87954320 0.7233519 0.5630988 2 x1.2 tr 0.06132255 0.8426960 0.3338658 0.04685878 0

Count files each user has uploaded and approved

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am building a Django app for uploading files. I would like to be able to count the number of files a users has and which are approved. I have a model with a Boolean 'approved' field. This model is in admin.py. In admin.py from django.contrib import admin from .models import FileModel from .forms import FileForm class FileModelAdmin(admin.ModelAdmin): form = FileForm fields = ('title', 'description', 'categories', 'pub_date', 'submitted_date', 'author', 'user', 'approved', 'upload', 'vote') # pass list_display = ['title', 'approved',

XSLT 1.0 Using position() in <xsl:for-each> and <xsl:template>

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: My understanding is that the usage of <xsl:template /> and <xsl:for-each> almost serve the same purpose and <xsl:for-each > is a sort of "anonymous inline template" . Question: However, considering the below scenario, i think using <xsl:for-each> is more appropriate. Please validate my understanding, or is there a way the output can be achieved through <xsl:template> as well? Input XML: <?xml version="1.0" encoding="UTF-8"?> <books> <book.child.1> <title>charithram</title> <author>sarika</author> </book.child.1> <book.child.2> <title

How to impute each categorical column in numpy array

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: There are good solutions to impute panda dataframe. But since I am working mainly with numpy arrays, I have to create new panda DataFrame object, impute and then convert back to numpy array as follows: nomDF=pd.DataFrame(x_nominal) #Convert np.array to pd.DataFrame nomDF=nomDF.apply(lambda x:x.fillna(x.value_counts().index[0])) #replace NaN with most frequent in each column x_nominal=nomDF.values #convert back pd.DataFrame to np.array Is there a way to directly impute in numpy array? 回答1: We could use Scipy's mode to get the highest value in

MS Excel VBA: Border Around Each Printed Page

匿名 (未验证) 提交于 2019-12-03 01:40:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I got the VBA code below to add borders around the printed pages of an excel (MS Excel 2013) worksheet but I got error codes as follows: "Runtime Error '1004': Application-defined or object-defined error". The debug highlighted the lines in block quotes. How do I resolve this please? Sub Create_Borders_Around_Pages() Dim rngBorder As Range Dim lngLastRow As Long Dim lngLastCol As Long Dim lngHPBreak As Long Dim lngVPBreak As Long Dim lngRow As Long Dim lngCol As Long Dim rngAC As Range With ActiveSheet Set rngAC = ActiveCell lngLastRow =

checking each required input for empty value with jQuery

匿名 (未验证) 提交于 2019-12-03 01:39:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am checking for each required fields in a form. I tried this but it only works for the first input. How can I make it work for each input? if($('[required]').val() != ''){ $('.button1').fadeIn(0); $('.button2').fadeOut(0); }else{ $('.button1').fadeOut(0); $('.button2').fadeIn(0); } EDIT : for more context, here's another function I had below this to apply whenever they change and HTML code. $('[required]').change(function() { if($('[required]').val() != ''){ $('.button1').fadeIn(0); $('.button2').fadeOut(0); }else{ $('.button1').fadeOut(0)

Only one usage of each socket address (protocol/network address/port) is normally permitted

匿名 (未验证) 提交于 2019-12-03 01:39:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: The last few weeks we have been experiencing this error message while using the Azure Search SDK (1.1.1 - 1.1.2) and performing searches. We consume the Search SDK from internal APIs (deployed as Azure Web Apps) that scale up-down based on traffic (so there could be more than 1 instance of the APIs doing the searches). Our API queries 5 different indexes and maintains an in-memory copy of the SearchIndexClient object that corresponds to each index, a very simple implementation would look like: public class AzureSearchService {