array

Dumping variant array to range - VBA excel error 1004

匿名 (未验证) 提交于 2019-12-03 01:54:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm using vba for Excel in order to save data into an array by: Dim allPosts As Variant allPosts = Range ( "A2:J5000" ) after that I'm changing data in the allPosts array, and then I want to paste it back by: Range ( "A2:J5000" ). Value = allPosts I'm getting the error: run time error 1004 Application-defined or object-defined and the copy stops at a specific cell, when i change the string at this cell to be shorter the problem is solved. thanks 回答1: You can use a second array to store the cell lengths that are too long, and

Numpy Vector (N,1) dimension -> (N,) dimension conversion

匿名 (未验证) 提交于 2019-12-03 01:54:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a question regarding the conversion between (N,) dimension arrays and (N,1) dimension arrays. For example, y is (2,) dimension. A=np.array([[1,2],[3,4]]) x=np.array([1,2]) y=np.dot(A,x) y.shape Out[6]: (2,) But the following will show y2 to be (2,1) dimension. x2=x[:,np.newaxis] y2=np.dot(A,x2) y2.shape Out[14]: (2, 1) What would be the most efficient way of converting y2 back to y without copying? Thanks, Tom 回答1: reshape works for this a = np.arange(3) # a.shape = (3,) b = a.reshape((3,1)) # b.shape = (3,1) b2 = a.reshape((-1,1)) #

Searching array reports “not found” even though it's found

匿名 (未验证) 提交于 2019-12-03 01:54:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This is a generic question and answer for a logical error I've seen in many questions from new programmers in a variety of languages. The problem is searching an array for an element that matches some input criteria. The algorithm, in pseudo-code, looks something like this: for each element of Array: if element matches criteria: do something with element maybe break out of loop (if only interested in first match) else: print "Not found" This code reports "Not found" even if it successfully finds a matching element. 回答1: The problem is that

sklearn Logistic Regression “ValueError: Found array with dim 3. Estimator expected <= 2.”

匿名 (未验证) 提交于 2019-12-03 01:54:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I attempt to solve this problem 6 in this notebook. The question is to train a simple model on this data using 50, 100, 1000 and 5000 training samples by using the LogisticRegression model from sklearn.linear_model. https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/udacity/1_notmnist.ipynb lr = LogisticRegression() lr.fit(train_dataset,train_labels) This is the code i trying to do and it give me the error. ValueError: Found array with dim 3. Estimator expected Any idea? 回答1: scikit-learn expects 2d num arrays for the

python numpy array of arbitrary length strings

匿名 (未验证) 提交于 2019-12-03 01:52:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 选择语言 中文(简体) 日语 英语 中文(繁体) 由 翻译 强力驱动 问题: I'm a complete rookie to Python, but it seems like a given string is able to be (effectively) arbitrary length. I.e. you can take a string str and keeping adding to it: str += "some stuff..." . Is there a way to make an array of such strings? When I try this, each element only stores a single character strArr = numpy . empty ( 10 , dtype = 'string' ) for i in range ( 0 , 10 ) strArr [ i ] = "test" On the other hand, I know I can initialize an array of certain length strings, i.e. strArr = numpy . empty ( 10

IndexError: too many indices for array

匿名 (未验证) 提交于 2019-12-03 01:52:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I know there is a ton of these threads but all of them are for very simple cases like 3x3 matrices and things of that sort and the solutions do not even begin to apply to my situation. So I'm trying to graph G versus l1 (that's not an eleven, but an L1). The data is in the file that I loaded from an excel file. The excel file is 14x250 so there are 14 arguments, each with 250 data points. I had another user (shout out to Hugh Bothwell!) help me with an error in my code, but now another error has surfaced. So here is the code in question: #

How to quickly update a large BufferGeometry?

匿名 (未验证) 提交于 2019-12-03 01:52:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm using a BufferGeometry to draw thousands of cubes which makes up the terrain, but having a hard time finding out how to update the geometry if I need to change the position of one of the cubes. For example, I have this code to initialize my geometry: (I'm doing my testing on an updated version of this example ) // 12 triangles per cube (6 quads) var triangles = 12 * 150000 ; var geometry = new THREE . BufferGeometry (); geometry . attributes = { position : { itemSize : 3 , array : new Float32Array ( triangles * 3 * 3 ),

Working around IE8's broken Object.defineProperty implementation

匿名 (未验证) 提交于 2019-12-03 01:52:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Consider the following code, using ECMAScript5's Object.defineProperty feature: var sayHi = function(){ alert('hi'); }; var defineProperty = (typeof Object.defineProperty == 'function'); if (defineProperty) Object.defineProperty(Array.prototype,'sayHi',{value:sayHi}); else Array.prototype.sayHi = sayHi; var a = []; a.sayHi(); This works for Chrome and Firefox 4 (where defineProperty exists), and it works for Firefox 3.6 (where defineProperty does not exist). IE8, however, only partially supports defineProperty . As a result, it attempts to

How can I check whether the numpy array is empty or not?

匿名 (未验证) 提交于 2019-12-03 01:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How can I check whether the numpy array is empty or not? I used the following code, but this is fail if the array contains a zero. if not self.Definition.all(): is this the solution? if self.Definition == array( [] ): 回答1: You can always take a look at the .size attribute: import numpy as np a = np.array([]) print a.size # 0 回答2: http://www.scipy.org/Tentative_NumPy_Tutorial#head-6a1bc005bd80e1b19f812e1e64e0d25d50f99fe2 NumPy's main object is the homogeneous multidimensional array. In Numpy dimensions are called axes. The number of axes is

Array slices in C#

匿名 (未验证) 提交于 2019-12-03 01:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How do you do it? Given a byte array: byte[] foo = new byte[4096]; How would I get the first x bytes of the array as a separate array? (Specifically, I need it as an IEnumerable ) This is for working with Socket s. I figure the easiest way would be array slicing, similar to Perls syntax: @bar = @foo[0..40]; Which would return the first 41 elements into the @bar array. Is there something in C# that I'm just missing, or is there some other thing I should be doing? LINQ is an option for me (.NET 3.5), if that helps any. 回答1: Arrays are