About 176,000 results
Open links in new tab
  1. python - How to define a two-dimensional array? - Stack Overflow

    Jul 12, 2011 · Coming from other languages: it IS a difference between an 1D-Array containing 1D-Arrays and a 2D-Array. And AFAIK there is no way of having a multi-dimensional-array (or list) in python. Should be said here...

  2. python - Create a two-dimensional array with two one …

    If you wish to combine two 10 element one-dimensional arrays into a two-dimensional array, np.vstack((tp, fp)).T will do it. np.vstack((tp, fp)) will return an array of shape (2, 10), and the T attribute returns the transposed array with shape (10, 2) (i.e., with the two one-dimensional arrays forming columns rather than rows).

  3. How to initialize a two-dimensional array (list of lists, if not using ...

    @codemuncher The reason that [[0] * col] * row doesn't do what you want is because when you initialize a 2d list that way, Python will not create distinct copies of each row. Instead it will init the outer list with pointers to the same copy of [0]*col .

  4. python - Create 2D array from Pandas dataframe - Stack Overflow

    Nov 17, 2015 · I have a data frame with 9 columns and ~100000 rows. The data was extracted from an image, such that two columns ('row' and 'col') are referring to the pixel position of the data. How can I create a numpy array A such that the row and column points to another data entry in another column, e.g. 'grumpiness'? A[row, col] # 0.1232

  5. python - 2d array of zeros - Stack Overflow

    There is no array type in python, but to emulate it we can use lists. I want to have 2d array-like structure filled in with zeros. My question is: what is the difference, if any, in this two expressions: zeros = [[0 for i in xrange(M)] for j in xrange(M)] and. zeros = [[0]*M]*N

  6. Two dimensional array in python - Stack Overflow

    Create an array of list with initial values filled with 0 or anything using the following code. z=[[0 for row in range(0,x)] for col in range(0,y)] creates number of rows and columns for your array data. Read data from standard input: for i in range(x): for j in range(y): z[i][j]=input() Display the Result:

  7. python - How can I create a 2d array of integers? - Stack Overflow

    Oct 16, 2019 · There is also full_like , the main difference is to use the shape of an existing array and create another with the same shape but you can put any setting value here an example : import numpy as np x = np.arange(6).reshape(2,3) # so x =np.array([[1,2,3], [4,5,6])

  8. python - Merging 1D arrays into a 2D array - Stack Overflow

    Mar 16, 2018 · Is there a built-in function to join two 1D arrays into a 2D array? Consider an example: X=np.array([1,2]) y=np.array([3,4]) result=np.array([[1,3],[2,4]]) I can think of 2 simple solutions. The first one is pretty straightforward. np.transpose([X,y]) The other one employs a lambda function. np.array(list(map(lambda i: [a[i],b[i]], range(len(X)))))

  9. python - Convert a 1D array to a 2D array in numpy - Stack Overflow

    Sep 25, 2012 · I want to convert a 1-dimensional array into a 2-dimensional array by specifying the number of columns in the 2D array. Something that would work like this: > import numpy as np > A = np.arr...

  10. 2D arrays in Python - Stack Overflow

    In Python one would usually use lists for this purpose. Lists can be nested arbitrarily, thus allowing the creation of a 2D array. Not every sublist needs to be the same size, so that solves your other problem. Have a look at the examples I linked to.