apply

angular doesn't apply changes to array(remove item on socket event)

你。 提交于 2019-12-13 05:16:15
问题 First of all, sorry for my english, i'm ukrainian When socketio card delete event performed, there is nothing changed in view ng-repeat in my view <card object="item" ng-repeat="item in LOG"></card> In my controller $scope.LOG = [{...},...{...}]; SocketIO emit socket.on('card_was_deleted', function (data) { $scope.open_object = undefined; $scope.LOG = $scope.LOG.filter(function (obj) { return obj.ID != data.id; }); });//or var index = ...;$scope.LOG.splice(index, 1); I was looking for $scope.

12-09新随笔【防抖,节流 call/apply】

余生长醉 提交于 2019-12-13 05:10:51
12/9 新随笔 1.防抖 //防抖 function debounce ( params ) { let timeout = null ; return function ( ) { clearTimeout ( timeout ) ; timeout = setTimeout ( ( ) => { params . apply ( this , arguments ) ; } , 500 ) ; } ; } function sayHi ( ) { console . log ( 'successful' ) ; } var inp = document . getElementById ( 'inp' ) ; inp . addEventListener ( 'input' , debounce ( sayHi ) ) ; 2.节流 //节流 function throttle ( fn ) { let canRun = true ; // 通过闭包保存一个标记 return function ( ) { if ( ! canRun ) return ; // 在函数开头判断标记是否为true,不为true则return canRun = false ; // 立即设置为false setTimeout ( ( ) => { //

R lapply convert NA's to 0

风格不统一 提交于 2019-12-13 04:53:42
问题 I'm trying to convert a subset of columns from NA's to 0's using the following code. Unfortunately it turns all the cells to 0's. df1 <- data.frame(id = 1:20, col1 = runif(20), col2 = runif(20), col3 = runif(20)) df1[sample(1:20,5),'col1'] <- NA df1[sample(1:20,5),'col2'] <- NA df1[sample(1:20,5),'col3'] <- NA subset1 <- c('col1','col2','col3') df1[,subset1] <- as.data.frame(lapply(df1[,subset1], function(x) x[is.na(x)] <- 0)) Any suggestions? 回答1: Try this simple approach df1[is.na(df1),] <-

Angular - update scope in Directive

耗尽温柔 提交于 2019-12-13 03:48:10
问题 I'm having problems updating a scope var in a directive, I don't want to have to add HTML in the directive, is it possible to just have the value of the scope var updated. The get-event links will update a variety of text / links / images, but first I just want it to update the scope var name Index.jade div(ng-controller='AppCtrl') h2 Hello {{name}} a(href={{link}}) test a.playlist(get-event rel='1000') 1000 br br a.playlist(get-event rel='2000') 2000 br br a.playlist(get-event rel='3000')

Pandas apply multiple columns per row instead of list

时光总嘲笑我的痴心妄想 提交于 2019-12-13 02:57:40
问题 I have trouble making pandas returning multiple columns when using apply. Example: import pandas as pd import numpy as np np.random.seed(1) df = pd.DataFrame(index=range(2), columns=['a', 'b']) df.loc[0] = [np.array((1,2,3))], 1 df.loc[1] = [np.array((4,5,6))], 1 df a b 0 [[1, 2, 3]] 1 1 [[4, 5, 6]] 1 df2 = np.random.randint(1,9, size=(3,2)) df2 array([[4, 6], [8, 1], [1, 2]]) def example(x): return np.transpose(df2) @ x[0] df3 = df['a'].apply(example) df3 0 [23, 14] 1 [62, 41] I want df3 to

Adding columns sums in dataframe row wise conditional on a dummy

不想你离开。 提交于 2019-12-13 01:27:51
问题 I would like to add the sums of the columns of my dataframe one row at a time, conditional on another column that has a binary variable. So for each row, I would like to compute the sum of the entire column above it for all rows where the binary variable in the corresponding row has the same value. Here is an example: dummy var1 var2 1 x1 y1 0 x2 y2 0 x3 y3 1 x4 y4 My goal is to obtain this: dummy var1 var2 1 x1 y1 0 x2 y2 0 x3+x2 y3+y2 1 x4+x1 y4+y1 I have asked this question previously for

Applying a function across nested list

非 Y 不嫁゛ 提交于 2019-12-13 01:16:58
问题 Say, I have the following list raw <- list(list(1:2, 2:3, 3:4), list(4:5, 5:6, 6:7), list(7:8, 8:9, 9:10)) I would like to find the mean of the corresponding entries of the out-most list. The expected output would be something like [[1]] [1] 4 5 [[2]] [1] 5 6 [[3]] [1] 6 7 This is because the mean of 1:2 , 4:5 , and 7:8 would be 4:5 . I have been experimenting with stuff like lapply(raw, function(x) lapply(x, mean)) , but apparently it doesn't return the desired output. 回答1: This is pretty

speed up python apply row wise functions

ぃ、小莉子 提交于 2019-12-13 00:19:03
问题 I am working on one of the data cleansing project, I have to clean multiple fields of a pandas data frame as part of it. Mostly I am writing regular expressions and simple functions. Examples below, def func1(s): s = str(s) s = s.replace(' ', '') if len(s) > 0 and s != '0': if s.isalpha() and len(s) < 2: return s def func2(s): s = str(s) s = s.replace(' ', '') s = s.strip(whitespace+','+'-'+'/'+'\\') if s != '0': if s.isalnum() or s.isdigit(): return s def func3(s): s = str(s) if s.isdigit()

Set background/opaque to all JLabels

会有一股神秘感。 提交于 2019-12-12 18:26:22
问题 See my code: package hsleiden.webcat.exercise12_08; import java.awt.*; import javax.swing.*; import javax.swing.border.Border; public class newFrame extends JFrame { public static void main(String[] args){ newFrame frame = new newFrame(); frame.setLayout(new GridLayout(2,3)); frame.setSize(200, 200); frame.setTitle("Opdracht 12.8"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); frame.setVisible(true); } public newFrame(){ JLabel label1 = new JLabel(

Javascript call and apply functions only called on first argument?

拈花ヽ惹草 提交于 2019-12-12 15:45:25
问题 Edit: this question was asked due to my misunderstanding. Proceed with caution, as reading it might waste your time. I thought call and apply would execute a function given a set of arguments, but I'm getting confusing test results. See my test code: window.z = 0; (function(){++(window.z)}).call(this, 1, 2, 3) I would expect z to be 3 after execution. However, z is 1. (function(){++(window.z)}).apply(this, [1, 2, 3]) Same here. z == 1; I tried simply logging the input argument as well: var x