array

Convert cell array of cell arrays to matrix of matrices

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I can convert a cell array of matrices to matrix: >> C={[1,1]; [2,2]; [3,3]}; >> cell2mat(C) ans = 1 1 2 2 3 3 This is OK. But, I want to convert a cell array including other cell arrays to a matrix: >> C={{1,1}; {2,2}; {3,3}}; >> cell2mat(C) Error using cell2mat (line 53) Cannot support cell arrays containing cell arrays or objects. So, desired output is: >> mycell2mat({{1,1}; {2,2}; {3,3}}) ans = 1 1 2 2 3 3 How to do this? Edit: I want to do same thing for multidimensional ones also: >> mycell2mat({{1,1;1,1}; {2,2;2,2}; {3,3;3,3}}) ans(:,

What is __flexarr and how/why do c programmers use it?

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In sys/inotify.h ( inotify.h ), following struct is defined: struct inotify_event { int wd; /* Watch descriptor. */ uint32_t mask; /* Watch mask. */ uint32_t cookie; /* Cookie to synchronize two events. */ uint32_t len; /* Length (including NULs) of name. */ char name __flexarr; /* Name. */ }; I can't find any definitions for __flexarr in the code. Where would I search for it? In an unrelated project I found #define __flexarr [1] which I assume does something similar, but this definition does not make much sense to me (being quite unfamiliar

Processing a very very big data set in python - memory error

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to process data obtained from a csv file using csv module in python. there are about 50 columns & 401125 rows in this. I used the following code chunk to put that data into a list csv_file_object = csv.reader(open(r'some_path\Train.csv','rb')) header = csv_file_object.next() data = [] for row in csv_file_object: data.append(row) I can get length of this list using len(data) & it returns 401125. I can even get each individual record by calling list indices. But when I try to get the size of the list by calling np.size(data) (I

C++ Error: Incompatible types in assignment of ‘char*’ to ‘char [2]

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a bit of a problem with my constructor. In my header file I declare: char short_name_[2]; and other variables In my constructor: Territory(std::string name, char short_name[2], Player* owner, char units); void setShortName(char* short_name); inline const char (&getShortName() const)[2] { return short_name_; } In my cpp file: Territory::Territory(std::string name, char short_name[2], Player* owner, char units) : name_(name), short_name_(short_name), owner_(owner), units_(units) { } My error: Territory.cpp: In constructor ‘Territory:

'numpy.float64' object is not iterable

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to iterate an array of values generated with numpy.linspace: slX = numpy.linspace(obsvX, flightX, numSPts) slY = np.linspace(obsvY, flightY, numSPts) for index,point in slX: yPoint = slY[index] arcpy.AddMessage(yPoint) This code worked fine on my office computer, but I sat down this morning to work from home on a different machine and this error came up: File "C:\temp\gssm_arcpy.1.0.3.py", line 147, in AnalyzeSightLine for index,point in slX: TypeError: 'numpy.float64' object is not iterable slX is just an array of floats, and the

Create a 100 % stacked area chart with matplotlib

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I was wondering how to create a 100 % stacked area chart in matplotlib. At the matplotlib page I couldn't find an example for it. Somebody here can show me how to achieve that? 回答1: A simple way to achieve this is to make sure that for every x-value, the y-values sum to 100. I assume that you have the y-values organized in an array as in the example below, i.e. y = np.array([[17, 19, 5, 16, 22, 20, 9, 31, 39, 8], [46, 18, 37, 27, 29, 6, 5, 23, 22, 5], [15, 46, 33, 36, 11, 13, 39, 17, 49, 17]]) To make sure the column totals are 100, you have

Ignore empty cells PHPExcel

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using the library PHPExcel to read data in an Excel file. The problem I'm having, is that when I use something like: $obj = PHPExcel_IOFactory::load($file); $data = $obj->getActiveSheet()->toArray(null,true,true,true); To load my file and convert its content into an array, I get all the columns and rows of my Excel file in my array even those without any data in them. Is there a method or something in the library PHPExcel to tell it to ignore cells in my Excel sheet that do not contain any data? (Instead of having a bunch of empty

C++ error: “Array must be initialized with a brace enclosed initializer”

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am getting the following C++ error: array must be initialized with a brace enclosed initializer From this line of C++ int cipher[Array_size][Array_size]; What is the problem here? What does the error mean? Below is the full code: string decryption(string todecrypt) { int cipher[Array_size][Array_size] = 0; string ciphercode = todecrypt.substr(0,3); todecrypt.erase(0,3); decodecipher(ciphercode,cipher); string decrypted = ""; while(todecrypt.length()>0) { string unit_decrypt = todecrypt.substr(0,Array_size); todecrypt.erase(0,Array_size);

In JavaScript, why is [ ] preferred over new Array();?

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I remember reading somewhere (I think it was in one of Crockford's papers) that using an array literal [] is better than using the new Array(); notation. But I can't really remember any advantages of one over the other. Can anyone please explain to me on why the former is preferred over the latter? Here is one reason I can think of on why [] is better than new Array(); : var Array = function () { }; Overriding the Array object will break code...! Any more reasons? 回答1: Brevity It has less bytes to transfer over the wire, less bytes to

How to determine if one array contains all elements of another array in Swift?

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have 2 arrays: var list : Array < Int > = [ 1 , 2 , 3 , 4 , 5 ] var findList : Array < Int > = [ 1 , 3 , 5 ] I want to determine if list Array contains all findList elements. By the way, elements might be String as well or other type. How to do that? I know that Swift provides contains method that works with one item. 回答1: Instead of iterating through arrays and doing filtering yourself, you can use NSSet to do all the work for you. var list : Array < Int > = [ 1 , 2 , 3 , 4 , 5 ] var findList : Array < Int > = [ 1 , 3 , 5 ] let