sequences

Assign sequential count for numerical runs

被刻印的时光 ゝ 提交于 2020-01-01 05:42:14
问题 I'd like to assign a cumulative numerical value for sequential runs in a binary vector. What I have is x = [0 0 0 1 1 0 1 1 1 0 1 0 0 0 0 0 0], and what I would like is y = [1 2 3 1 2 1 1 2 3 1 1 1 2 3 4 5 6]. The solution using sum/cumsum/unique/find range of functions alludes me. Any help would be greatly appreciated. 回答1: Here's a way: a = arrayfun(@(x)(1:x), diff(find([1,diff(x),1])), 'uni', 0); [a{:}] The idea is to generate a list of the 'run lengths', i.e. [3,2,1,3,1,1,6] in your case,

Programmatic access to On-Line Encyclopedia of Integer Sequences

你。 提交于 2019-12-31 09:15:33
问题 Is there a way to search and retrieve the results from On-Line Encyclopedia of Integer Sequences (http://oeis.org) programmatically? I have searched their site and the results are always returned in html. They do not seem to provide an API but in the policy statement they say its acceptable to access the database programmatically. But how to do it without screen scraping? Thanks a lot for your help. 回答1: The OEIS now provides several points of access, not just ones using their internal format

Given a string of integers find out all the possible words that can made out of it in continuous order. [closed]

谁说胖子不能爱 提交于 2019-12-31 07:42:18
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . Given a string of integers how to find out all the possible words that can made out of it in continuous order. Eg: 11112 ans: AAAAB AKAB AAKB AAAL etc. public static void main(String[] args) { String str="11111124"; char strChar[]=str.toCharArray(); String target=""; for(int i=0;i<strChar.length;i++) { target

saving an image sequence from video using opencv2

限于喜欢 提交于 2019-12-30 11:14:07
问题 Newbie question and yes I have spent a lot of time sifting through similar questions and Answers with no luck. What I am trying to do is save frames from a video file in a sequential order. I have managed to save one image using c and I cannot seem to save images after that. I have started using c++ in opencv instead of c and all I can do is view the video and not save any jpg's from it. I am using opencv2.4.4a on mac if that helps. below is my c example #include <stdio.h> #include <stdlib.h>

saving an image sequence from video using opencv2

南笙酒味 提交于 2019-12-30 11:13:05
问题 Newbie question and yes I have spent a lot of time sifting through similar questions and Answers with no luck. What I am trying to do is save frames from a video file in a sequential order. I have managed to save one image using c and I cannot seem to save images after that. I have started using c++ in opencv instead of c and all I can do is view the video and not save any jpg's from it. I am using opencv2.4.4a on mac if that helps. below is my c example #include <stdio.h> #include <stdlib.h>

Creating a sequence for a varchar2 field in Oracle

ぃ、小莉子 提交于 2019-12-30 10:24:05
问题 I want to create a sequence for this varchar. It would have been easier had it been a number instead of varchar. In that case, I could do seq_no := seq_no + 1; But what can I do when I want to store next value in column as A0000002, when the previous value was A0000001 (to increment the number in the next varchar rowby 1)? 回答1: This can be done by to_char(seq_no,'FM0000000') your example can be done by creating sequence in oracle create sequence seq_no start with 1 increment by 1; then select

Mapping into a tree of nested sequences

狂风中的少年 提交于 2019-12-25 18:41:12
问题 I've coded a function that aims to map into an arbitrary tree of nested proper lists, somewhat analogous to the common lisp function map-into : (defun map-into-tree (fn tree) "Destructive mapping into a proper tree." (cond ((null tree) nil) ((atom (car tree)) (setf (car tree) (funcall fn (car tree))) (map-into-tree fn (cdr tree))) (t (map-into-tree fn (car tree)) (map-into-tree fn (cdr tree))))) (defparameter *tree* '(1 (2) ((3)) (4 5) (6 ((7))))) *TREE* (map-into-tree #'1+ *tree*) NIL *tree*

Construct sequences from a dataframe using dictionaries in Python

冷暖自知 提交于 2019-12-25 08:05:18
问题 I would like to construct sequences of user's purchasing history using dictionaries in Python. I would like these sequences to be ordred by date. I have 3 columns in my dataframe: users items date 1 1 date_1 1 2 date_2 2 1 date_3 2 3 date_1 4 5 date_2 4 1 date_5 4 3 date_3 And the result should be like this : {1: [[1,date_1],[2,date_2]], 2:[[3,date_1],[5,date_2],[1,date_3]], 4:[[5,date_2],[3,date_3][1,date_5]]} My code is : df_sub = df[['uid', 'nid', 'date']] dic3 = df_sub.set_index('uid').T

Fill sequence in sql rows

本小妞迷上赌 提交于 2019-12-25 01:34:44
问题 I have a table that stores a group of attributes and keeps them ordered in a sequence. The chance exists that one of the attributes (rows) could be deleted from the table, and the sequence of positions should be compacted. For instance, if I originally have these set of values: +----+--------+-----+ | id | name | pos | +----+--------+-----+ | 1 | one | 1 | | 2 | two | 2 | | 3 | three | 3 | | 4 | four | 4 | +----+--------+-----+ And the second row was deleted, the position of all subsequent

Finding the # of sequences in an array

跟風遠走 提交于 2019-12-24 08:39:32
问题 I need to report the # of sequences in an array. For example: A=[ 1 1 -1 -1 -1 -1 -1 0 1 -1 -1 -1 -1 1 1 -1 -1 1 0 1 1] and I have to report the # of times a number comes consecutively, such as, one sequence of 5 -1s ([-1 -1 -1 -1 -1]) and one sequence of 4 -1s ([-1 -1 -1 -1]) . How can I find how many sequences of numbers there are? 回答1: You may use run-length encoding to perform this task function [rl data] = runLength( vec ) % run length encoding for vector vec rl = ( find( vec ~= [vec(2