import numpy as np a = np.arange(36) print a.shape   (36,)  a = a.reshape(3,*(3,4)) print a.shape   (3,3,4)  Firstly, I think *(3,4) may be a parameter. So I  help(np.reshape).  a : array_like     Array to be reshaped. newshape : int or tuple of ints     The new shape should be compatible with the original shape. If     an integer, then the result will be a 1-D array of that length.     One shape dimension can be -1. In this case, the value is inferred     from the length of the array and remaining dimensions. order : {'C', 'F', 'A'}, optional     Read the elements of `a` using this index order, and place the elements     into the reshaped array using this index order.  'C' means to     read / write the elements using C-like index order, with the last axis     index changing fastest, back to the first axis index changing slowest.     'F' means to read / write the elements using Fortran-like index order,     with the first index changing fastest, and the last index changing     slowest.     Note that the 'C' and 'F' options take no account of the memory layout     of the underlying array, and only refer to the order of indexing.  'A'     means to read / write the elements in Fortran-like index order if `a`     is Fortran *contiguous* in memory, C-like order otherwise.   I can not find the correct parameter which can match *(3,4).So how can I comprehend the usage of *(3,4) in this way?
866
In the following method definitions, what does the * and ** do for param2?  def foo(param1, *param2): def bar(param1, **param2):
72069
Given [1,2,3,4,5], how can I do something like   1/1, 1/2, 1/3,1/4,1/5, ...., 3/1,3/2,3/3,3/4,3/5,.... 5/1,5/2,5/3,5/4,5/5   I would like to store all the results, find the minimum, and return the two numbers used to find the minimum. So in the case I've described above I would like to return (1,5).  So basically I would like to do something like  for each element i in the list map some function across all elements in the list, taking i and j as parameters store the result in a master list, find the minimum value in the master list, and return the arguments i, jused to calculate this minimum value.  In my real problem I have a list objects/coordinates, and the function I am using takes two coordinates and calculates the euclidean distance. I'm trying to find minimum euclidean distance between any two points but I don't need a fancy algorithm.
82341
example:  a_list = [1, 2, 3] a_list.len() # doesn't work len(a_list) # works   Python being (very) object oriented, I don't understand why the 'len' function isn't inherited by the object.  Plus I keep trying the wrong solution since it appears as the logical one to me
111469
I do not want to use BMesh this time.  I want to create a mesh programmatically, for this purpose I created this short script to see what I do wrong in my importer script. In this script I try to create a tetraeder. First I create the mesh, then define the vertices. Then I go for the polygons, but here I do something bad, because at the end I got no polygons defined.  The code:  mesh = bpy.data.meshes.new("Teszt")  mesh.vertices.add(4) mesh.vertices[0].co = (0,0,0) mesh.vertices[1].co = (2,0,0) mesh.vertices[2].co = (1,2,0) mesh.vertices[3].co = (1,1,3)  mesh.polygons.add(4) mesh.polygons[0].vertices = (0,1,2) mesh.polygons[1].vertices = (0,1,3) mesh.polygons[2].vertices = (1,2,3)  mesh.polygons[3].vertices = (0,2,3) print(len(mesh.polygons[3].vertices))  mesh.polygons[3].vertices = [0,2,3] print(len(mesh.polygons[3].vertices))  #mesh.update()  #from bpy_extras import object_utils #object_utils.object_data_add(bpy.context, mesh)   I am pretty new to Python, so it may be totally my fault, but when I check the len of (0,2,3), that is 3, when I execute mesh.polygons[3].vertices = (0,2,3) it says 0. No exception or error message, just shallows it.  When I try to update() or ...data_add( at the end, Blender simply exits.  So my question is: how to define the polygons properly (and without using bmesh)?
100554
Is this telling the model that there are two dimensions (i.e. it’s a matrix) but we don’t yet know the size of that particular dimension? If so, how can the model be compiled? Doesn’t the size of each dimension affect the number of nodes in middle layers?
106
I need a good explanation (references are a plus) on Python's slice notation.   To me, this notation needs a bit of picking up.   It looks extremely powerful, but I haven't quite got my head around it.
87286
Just reading about the cross product. It says here: $$A\times B= \{(x,y)|x\in A, y\in B\}$$ Does this mean that the result of $A\times B$ is a new set of ordered pairs? If so, what happens if both A and B share a common member? What would the result be, since an ordered pair cannot include duplicates?    Edit: Quoting the free textbook I'm looking at online,     If we are given that A is a set and no other information about A, then there is no   ordering to the elements of A. Thus, we cannot speak of “the second element of the set A”   unless we have specified an ordering of the elements of A. If we wish to regard A as ordered in some way, then we specify this fact explicitly: “The elements of A are ordered a, b, c,” or “A = (a, b, c).” The latter notation replaces the braces with parentheses and designates that A is ordered, left to right, as indicated. We call this an ordered set. An ordered set is also called a linear order. Various other names are also used: list, vector, string, word — all with no repeated elements. Of course, you’ve seen repeated elements in vectors, for example the point in the plane at the coordinates (1,1). That’s fine, it’s just not an ordered set.       Why is it okay to specify a set S = {a, b, c, a} where the element a has been repeated,   but it is not okay to have repeated elements in an ordering of S?   When we say S  =   {a, b, c, a}, we know that S contains just the three elements a, b and c.  If we were to talk   about the ordered set (a, b, c, a) it would not make sense because it would say that the   element a is in two places at once: the first position and the last position.
27323
I can't figure out how to use an array or matrix in the way that I would normally use a list. I want to create an empty array (or matrix) and then add one column (or row) to it at a time.  At the moment the only way I can find to do this is like:  mat = None for col in columns:     if mat is None:         mat = col     else:         mat = hstack((mat, col))   Whereas if it were a list, I'd do something like this:  list = [] for item in data:     list.append(item)   Is there a way to use that kind of notation for  arrays or matrices?
119103
Omg this is driving me crazy seriously, it's a subproblem for a bigger problem, and i'm stuck on it.  Anyways i need the number of ways to pick $x[1]$ ammount of objects type $1$, $x[2]$ ammount of objects type $2$, $x[3]$ ammounts of objects type $3$ etc etc such that $$x[1] + x[2] + \ldots x[n] = k\;.$$ Order of the objects of course doesn't matter.  I know there is a simple formula for this something like $\binom{k + n}n$ or something like that i just can't find it anywhere on google.
28322
We transpose a matrix $A$ by replacing $A_{ij}$ with $A_{ji}$, for all $i$ and $j$.  However, in case $A$ has more than two dimensions (that is, it is a tensor), I don't know how to apply the transpose operation.   If A has dimensions $3\times 3 \times 8$, then what will replace $A_{ijk}$?  If $A$ has shape $3\times 3\times 8\times 8$, then what will replace $A_{ijkl}$?
17923
I have an array in the form of 'int[][]' that represents the co-ordinates of a small grid. Each co-ordinate has been assigned its own value. eg array[0][4] = 28......  I have two questions. Firstly, how do I iterate through all the stored values. Secondly, I want to be able to input a value and have its specific co-ordinates in the grid returned. What would be the best way to approach this?  Thank you for any help!
11649
I've created polygons from a table that has two columns- an OBJECTID and a string of coordinates (Polygon_Coordinates). The resulting polygons (called &quot;testing&quot; in the code below) are in the correct locations, but I can't seem to figure out how to carry over the ID, which I need for a join later in the workflow. Any idea on how to build geometry, but maintain the attributes? fields = ['Polygon_Coordinates', 'OBJECTID']  with arcpy.da.SearchCursor(table, fields) as table_cursor:     for row in table_cursor:         #skip null rows         if row[0] != '-9999':                          #turn string of coordinates into a list but split them at the commas             coords= list(row[0].split(','))                          #break up list into list of pairs             pairs = [coords[i:i + 2] for i in range(0, len(coords), 2)]             coord_ints = [[float(i) for i in p] for p in pairs]              #create insert cursor for geometry creation             geocursor = arcpy.da.InsertCursor(testing, [&quot;SHAPE@&quot;])             array = arcpy.Array()                          #grab pairs from list, put into array             for a in pairs:                 array.add(arcpy.Point(a[1],a[0], ID=row[1]))                          #set crs, build polygon              wgs = arcpy.SpatialReference(4326)             poly = arcpy.Polygon(array, wgs)             geocursor.insertRow([poly])
6976
What's the simplest, most standard, and/or most efficient way to split a List into two sub-Lists in Java? It's OK to mutate the original List, so no copying should be necessary. The method signature could be  /** Split a list into two sublists. The original list will be modified to  * have size i and will contain exactly the same elements at indices 0   * through i-1 as it had originally; the returned list will have size   * len-i (where len is the size of the original list before the call)   * and will have the same elements at indices 0 through len-(i+1) as   * the original list had at indices i through len-1.  */ &lt;T&gt; List&lt;T&gt; split(List&lt;T&gt; list, int i);   [EDIT] List.subList returns a view on the original list, which becomes invalid if the original is modified. So split can't use subList unless it also dispenses with the original reference (or, as in Marc Novakowski's answer, uses subList but immediately copies the result).
116830
I am displaying a cube using a vertex buffer object (gl.ELEMENT_ARRAY_BUFFER). This allows me to specify vertex indicies, rather than having duplicate vertexes. In the case of displaying a simple cube, this means I only need to have eight vertices total. Opposed to needing three vertices per triangle, times two triangles per face, times six faces. Sound correct so far?  My question is, how do I now deal with vertex attribute data such as color, texture coordinates, and normals when reusing vertices using the vertex buffer object?  If I am reusing the same vertex data in my indexed vertex buffer, how can I differentiate when vertex X is used as part of the cube's front face versus the cube's left face? In both cases I would like the surface normal and texture coordinates to be different. I understand I could average the surface normal, however I would like to render a cube. Also, this still doesn't work for texture coordinates.  Is there a way to save memory using a vertex buffer object while being able to provide different vertex attribute data based on context? (Per-triangle would be idea.)  Or should I just duplicate each vertex for each context in which it gets rendered. (So there is a one-to-one mapping between vertex, normal, color, etc.)  Note: I'm using OpenGL ES.
50435
What is the memory layout of a .NET array?  Take for instance this array:  Int32[] x = new Int32[10];   I understand that the bulk of the array is like this:  0000111122223333444455556666777788889999   Where each character is one byte, and the digits corresponds to indices into the array.  Additionally, I know that there is a type reference, and a syncblock-index for all objects, so the above can be adjusted to this:  ttttssss0000111122223333444455556666777788889999         ^         +- object reference points here   Additionally, the length of the array needs to be stored, so perhaps this is more correct:  ttttssssllll0000111122223333444455556666777788889999         ^         +- object reference points here   Is this complete? Are there more data in an array?  The reason I'm asking is that we're trying to estimate how much memory a couple of different in-memory representations of a rather large data corpus will take and the size of the arrays varies quite a bit, so the overhead might have a large impact in one solution, but perhaps not so much in the other.  So basically, for an array, how much overhead is there, that is basically my question.  And before the arrays are bad squad wakes up, this part of the solution is a static build-once-reference-often type of thing so using growable lists is not necessary here.
112071
We had a discussion here at work regarding why fread() and fwrite() take a size per member and count and return the number of members read/written rather than just taking a buffer and size. The only use for it we could come up with is if you want to read/write an array of structures which aren't evenly divisible by the platform alignment and hence have been padded but that can't be so common as to warrant this choice in design. From :  The function fread() reads nmemb elements of data, each size bytes long, from the stream pointed to by stream, storing them at the location given by ptr.   The  function  fwrite()  writes  nmemb elements of data, each size bytes long, to the stream pointed to by stream, obtaining them from the location given by ptr.   fread() and fwrite() return the number of items successfully read or written (i.e., not the number of characters).  If an error occurs, or  the end-of-file is reached, the return value is a short item count (or zero).
30281
Why the shape (sB) is unknown in the following code ? How to avoid this ?  \documentclass[]{standalone} \usepackage{tikz,xparse} \usetikzlibrary{calc}  \tikzset{pics/.cd,     % Marque croix     Cross/.style args={#1 and #2}{%         code = {%         \draw[#2,rotate=45,scale=1.4] (0,#1 pt) -- (0,-#1 pt) ;         \draw[#2,rotate=-45,scale=1.4] (0,#1 pt) -- (0,-#1 pt) ;         }     },     Cross/.default={2 and black} }  \NewDocumentCommand{\Segment}{mO{}}{%     \begin{scope}[#2]     \path    (0,0) coordinate (sA) pic {Cross={1.5 and gray}}         -- (#1,0) coordinate (sB) pic {Cross={1.5 and gray}} ;     \draw (sA)--(sB) ; % Can't reuse (sB)     \end{scope} }   \begin{document}     \begin{tikzpicture}     \Segment{1.5}     \end{tikzpicture} \end{document}