concatenation

Numpy: Concatenating multidimensional and unidimensional arrays

泪湿孤枕 提交于 2019-12-18 12:16:47
问题 I have a 2x2 numpy array : x = array(([[1,2],[4,5]])) which I must merge (or stack, if you wish) with a one-dimensional array : y = array(([3,6])) by adding it to the end of the rows, thus making a 2x3 numpy array that would output like so : array([[1, 2, 3], [4, 5, 6]]) now the proposed method for this in the numpy guides is : hstack((x,y)) however this doesn't work, returning the following error : ValueError: arrays must have same number of dimensions The only workaround possible seems to

Merge some list items in a Python List

自闭症网瘾萝莉.ら 提交于 2019-12-18 10:39:57
问题 Say I have a list like this: [a, b, c, d, e, f, g] How do modify that list so that it looks like this? [a, b, c, def, g] I would much prefer that it modified the existing list directly, not created a new list. 回答1: On what basis should the merging take place? Your question is rather vague. Also, I assume a, b, ..., f are supposed to be strings, that is, 'a', 'b', ..., 'f'. >>> x = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] >>> x[3:6] = [''.join(x[3:6])] >>> x ['a', 'b', 'c', 'def', 'g'] Check out

Vertica: how can you concate values by some order?

我怕爱的太早我们不能终老 提交于 2019-12-18 07:23:20
问题 Suppose you have columns ID | A | B | C 1 | 3 | 1 | 2 2 | 5 | 9 | 1 3 | 1 | 2 | 3 and you want the columns concatenated such that the end result would look like ID | ABC_value_DESC | ABC_value_DESC_colnames 1 | 3,2,1 | A,C,B 2 | 9,5,1 | B,A,C 3 | 3,2,1 | C,B,A where you want to get the col values in Descending order within the new column ABC_value_DESC and then return corresponding name of column in the new column ABC_value_DESC_colnames . How can you do the concatenation of values of

Toeplitz matrix of toeplitz matrix

这一生的挚爱 提交于 2019-12-18 06:56:31
问题 I want to create a toeplitz matrix of toeplitz matrix. H1, H2 and H3 are toeplitz matrices already. My result should look like that: H1 0 0 H2 H1 0 H3 H2 H1 0 H3 H2 0 0 H3 The existing toeplitz-function only accepts vector, so I can't use it for matrix. Currently I'm using vstack to create the first column, then second column etc. and then I use hstack to merge all columns. This takes a lot of effort, since I have to specifically add np.zeros matrices at certain places. I can't think of a

Concatenate two or more optional string in Java 8

不问归期 提交于 2019-12-18 06:13:16
问题 I have a rather simple question for you guys. In Java 8 it was introduced the Optional type. I have two objects of type Optional<String> and I want to know which is the more elegant way to concatenate them. Optional<String> first = Optional.ofNullable(/* Some string */); Optional<String> second = Optional.ofNullable(/* Some other string */); Optional<String> result = /* Some fancy function that concats first and second */; In detail, if one of the two original Optional<String> objects was

Concat an integer to a String - use String literal or primitive from performance and memory point of view?

微笑、不失礼 提交于 2019-12-18 04:44:14
问题 Option 1: String newStr = someStr + 3 + "]"; Option 2: String newStr = someStr + "3" + "]"; Which option is better with regards to performance, memory and general practice? What are some recommended tools/ways I can use to measure memory usage of my code and its performance (besides measuring the start time and the end time and calculate the difference) 回答1: The first will become: StringBuilder sb = new StringBuilder (String.valueOf (someStr)); sb.append (3); sb.append ("]"); String newStr =

Concat strings by & and + in VB.Net

折月煮酒 提交于 2019-12-18 04:29:22
问题 Is there any difference between & and + operators while concatenating string? if yes, then what is difference? And if No, then why below code generating exception? Example: Dim s, s1, t As String Dim i As Integer s1 = "Hello" i = 1 s = s1 & i t = s1 + i //Exception here If s = t Then MessageBox.Show("Equal...") End If 回答1: & and + are both concatenation operators but when you specify an integer while using +, vb.net tries to cast "Hello" into integer to do an addition. If you change "Hello"

Python concatenation vs append speed on lists

岁酱吖の 提交于 2019-12-18 04:01:34
问题 Taking this snippet from interactivepython.org: def test1(): # concat l = [] for i in range(1000): l = l + [i] def test2(): # append l = [] for i in range(1000): l.append(i) concat 6.54352807999 milliseconds append 0.306292057037 milliseconds Where the bottom block is the run time. It says concatenation is O(k), where k is the "length of the list being concatenated". I'm not sure if this means the list you are adding to (original), or the list you are going to be adding. But in both these

strcat concat a char onto a string?

我是研究僧i 提交于 2019-12-18 03:33:53
问题 Using GDB, I find I get a segmentation fault when I attempt this operation: strcat(string,&currentChar); Given that string is initialized as char * string = ""; and currentChar is char currentChar = 'B'; Why does this result in a segmentation fault? If strcat can't be used for this, how else can I concat a char onto a string? 回答1: Because &currentChar is not a string, it doesn't finish with \0 character. You should define B as char *currentChar = 'B'; . Also according to http://www.cplusplus

How to concat two or more gzip files/streams

北慕城南 提交于 2019-12-18 02:41:14
问题 I want to concat two or more gzip streams without recompressing them. I mean I have A compressed to A.gz and B to B.gz, I want to compress them to single gzip (A+B).gz without compressing once again, using C or C++. Several notes: Even you can just concat two files and gunzip would know how to deal with them, most of programs would not be able to deal with two chunks. I had seen once an example of code that does this just by decompression of the files and then manipulating original and this