indexing

Subsetting vector: how to programatically pass negative index safely?

ぃ、小莉子 提交于 2020-01-03 16:47:12
问题 Given a vector, say v = 1:10 , one can remove elements from v using negative indexing, e.g. v[-1] , v[-length(v)] , v[-c(2,3)] , to remove the first, last and 2nd/3rd element respectively. I would like to split v by passing in a split index n , taking values 0 to length(v) . The code below: v1 <- v[1:n] v2 <- v[-c(1:n)] works perfectly fine except for n = 0 . Now I know that 1:n is generally unsafe and should be replaced with seq_len(n) , however, the assignment v2 <- v[-seq_len(0)] produces

CoffeeScript: How to return a array From class?

心已入冬 提交于 2020-01-03 16:44:31
问题 What is wrong in this class in CoffeeScript ?? @module "Euclidean2D", -> class @Point constructor: (x,y) -> return if Float32Array? then Float32Array([ x, y ]) else Array(x,y) I want it to behave like: p = new Point(1.0,2.0); p[0] == 1.0 p[1] == 2.0 But testing with Jasmine I get "Expected undefined to equal 1." describe "Point", -> beforeEach -> @point = new Euclidean2D.Point(1.0,2.0) it "extracts values", -> (expect @point[0]).toEqual 1.0 (expect @point[1]).toEqual 2.0 Is there an error in

Core Spotlight Userinfo is always empty

假装没事ソ 提交于 2020-01-03 14:16:49
问题 I am using a combination of CoreSpotlight api and NSUserActivity api to index app content. Everything goes well until I tap a search result. The userInfo passed with userActivity in continueUserActivity method contains only one item i.e kCSSearchableItemActivityIdentifier . My other custom keys are nil. Here is my code for indexing items.. class MyTestViewController:UIViewController{ viewDidLoad(){ searchHandler = SearchHandler() searchHandler.index(items) } } class SearchHandler{ var

How to get a welcome page from Tomcat root, rather than webapp context?

强颜欢笑 提交于 2020-01-03 14:02:22
问题 In Tomcat 7, I want my welcome page (index.html) to load when I access localhost:8080/. Right now, I have to go to the webapp context, localhost:8080/MyWebApp. Is there a folder in Tomcat to place pages that are not part of a webapp? I'm confused how this works... EDIT: I notice that the web.xml for the Server in Eclipse has a servlet called "default" which is mapped to "/"... I wonder if I have to change something here? EDIT2: I found this: http://wiki.apache.org/tomcat/HowTo#How_do_I

How to get a welcome page from Tomcat root, rather than webapp context?

自闭症网瘾萝莉.ら 提交于 2020-01-03 14:01:29
问题 In Tomcat 7, I want my welcome page (index.html) to load when I access localhost:8080/. Right now, I have to go to the webapp context, localhost:8080/MyWebApp. Is there a folder in Tomcat to place pages that are not part of a webapp? I'm confused how this works... EDIT: I notice that the web.xml for the Server in Eclipse has a servlet called "default" which is mapped to "/"... I wonder if I have to change something here? EDIT2: I found this: http://wiki.apache.org/tomcat/HowTo#How_do_I

Python Pandas: How can I group by and assign an id to all the items in a group?

允我心安 提交于 2020-01-03 13:56:07
问题 I have df: domain orgid csyunshu.com 108299 dshu.com 108299 bbbdshu.com 108299 cwakwakmrg.com 121303 ckonkatsunet.com 121303 I would like to add a new column with replaces domain column with numeric ids per orgid: domain orgid domainid csyunshu.com 108299 1 dshu.com 108299 2 bbbdshu.com 108299 3 cwakwakmrg.com 121303 1 ckonkatsunet.com 121303 2 I have already tried this line but it does not give the result I want: df.groupby('orgid').count['domain'].reset_index() Can anybody help? 回答1: You

DirectoryIndex doesn't work

我的梦境 提交于 2020-01-03 10:58:27
问题 I use apache2 to host a site. There are both index.html and index.php in my directory. I open the /etc/apache2/apache2.conf and add a line: DirectoryIndex index.php index.html index.htm Then restart apache2. But when I open localhost/~username , it accesses the index.html. I look around but can't find problem. My httpd.conf is empty and I don't have .htaccess file. Where may the setting hide? Edit : After I modified /etc/apache2/mods-availiable/dir.conf , it finds the index.php. But WHY the

How to implement n:m relation in Java?

怎甘沉沦 提交于 2020-01-03 10:56:08
问题 I need to implement an n:m relation in Java. The use case is a catalog. a product can be in multiple categories a category can hold multiple products My current solution is to have a mapping class that has two hashmaps. The key of the first hashmap is the product id and the value is a list of category ids The key to the second hashmap is the category id and the value is a list of product ids This is totally redundant an I need a setting class that always takes care that the data is stored

How to implement n:m relation in Java?

╄→尐↘猪︶ㄣ 提交于 2020-01-03 10:56:05
问题 I need to implement an n:m relation in Java. The use case is a catalog. a product can be in multiple categories a category can hold multiple products My current solution is to have a mapping class that has two hashmaps. The key of the first hashmap is the product id and the value is a list of category ids The key to the second hashmap is the category id and the value is a list of product ids This is totally redundant an I need a setting class that always takes care that the data is stored

index a bit field in MYSQL

扶醉桌前 提交于 2020-01-03 10:22:11
问题 updated question: suppose the data I'm interested in is only those with field=1 and the actual ratio of data wheere field is 1 vs 0 is very small(eg. 1%) in this case, would index the field benefit my select where field =1 query? original question: I have a int field that will have either 0 or 1 value, would indexing this field speed up select queries such as: select * from xxx where field=1; 回答1: Generally speaking, no. A bi-state field doesn't speed up queries when indexed because you have