About 383,000 results
Open links in new tab
  1. 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.array([1,2,3,4,5,6]) > B = vec2matrix(A,ncol=2) > B array([[1, 2], [3, 4], [5, 6]])

  2. Convert a 1D array to a 2D Numpy array - GeeksforGeeks

    Sep 8, 2022 · Convert a 1D array to a 2D Numpy array using numpy.reshape. Here, we are using np.reshape to convert a 1D array to 2 D array. You can divide the number of elements in your array by ncols.

  3. 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)))))

  4. Creating a one-dimensional NumPy array - GeeksforGeeks

    Jan 27, 2025 · We can create a 1-D array in NumPy using the array() function, which converts a Python list or iterable object. Python import numpy as np # Create a one-dimensional array from a list array_1d = np . array ([ 1 , 2 , 3 , 4 , 5 ]) print ( array_1d )

  5. Flatten a 2d numpy array into 1d array - GeeksforGeeks

    Feb 3, 2023 · Given a 2d numpy array, the task is to flatten a 2d numpy array into a 1d array. Below are a few methods to solve the task. Method #1 : Using np.flatten () [2 4 5] [1 2 3]] Time complexity: O (n), where n is the total number of elements in the 2D numpy array. Auxiliary space: O (n), as the result array is also of size n.

  6. How to transform 1D Array to 2D Array with duplication

    Nov 26, 2018 · Say I have a 1-dimensional numpy array with shape (5,): a = np.array(range(0,5)) And I want to transform it two a 2-dimensional array by duplicating the array above 3 times, so that the shape will be (5,3), for example: array([[0,1,2,3,4], [0,1,2,3,4], [0,1,2,3,4]]) How would I …

  7. Convert 1D array to 2D array in Python (numpy.ndarray, list)

    May 15, 2023 · This article explains how to convert a one-dimensional array to a two-dimensional array in Python, both for NumPy arrays ndarray and for built-in lists list.

  8. NumPy Creating Arrays - W3Schools

    These are the most common and basic arrays. Create a 1-D array containing the values 1,2,3,4,5: An array that has 1-D arrays as its elements is called a 2-D array. These are often used to represent matrix or 2nd order tensors. Create a 2-D array …

  9. Mastering NumPy Reshape: Converting 1D Arrays to 2D Arrays

    NumPy reshape 1d to 2d is a powerful technique that allows you to transform one-dimensional arrays into two-dimensional arrays, enabling more complex data manipulations and analyses.

  10. Converting a 1D Array to a 2D Array in NumPy - DNMTechs

    To convert a 1D array to a 2D array, we can make use of NumPy’s reshape() function. The reshape() function allows us to change the shape of an array without modifying its data. It takes the desired shape as an argument and returns a new array with the specified shape.

  11. Some results have been removed
Refresh