Answers for "numpy array"

6

numpy list to array

# importing library 
import numpy  
  
# initilizing list 
lst = [1, 7, 0, 6, 2, 5, 6] 
  
# converting list to array 
arr = numpy.array(lst) 
  
# displaying list 
print ("List: ", lst) 
  
# displaying array 
print ("Array: ", arr)
Posted by: Guest on May-27-2020
5

how to combine two arrays in python

# concatenate 2 numpy arrays: row-wise
>np.concatenate((array2D_1, array2D_2))
 
array([[ 0,  1,  2],
       [ 3,  4,  5],
       [ 6,  7,  8],
       [10, 11, 12],
       [13, 14, 15],
       [16, 17, 18]])
Posted by: Guest on April-06-2020
0

python numpy array

import numpy as np

ary=np.array([1, 2, 3, 4])

print(ary[0]) # 1
print(ary[2]) # 3
print(ary[::2]) # array([1, 3])
Posted by: Guest on October-08-2021
0

numpy array [-1]

print(b)
>>array([[ 0,  1,  2,  3],
       [10, 11, 12, 13],
       [20, 21, 22, 23],
       [30, 31, 32, 33],
       [40, 41, 42, 43]])

print(b[-1])       # the last row. Equivalent to b[-1,:]
>>array([40, 41, 42, 43])
Posted by: Guest on April-21-2021
0

np.array

x = np.array([ [67, 63, 87],
               [77, 69, 59],
               [85, 87, 99], # Creates an array, with arrays 
               [79, 72, 71],
               [63, 89, 93],
               [68, 92, 78]])
               
# its shape is [6,3] | 6 beeing its "height" and 3 its "width"

# if you want to to get this inffo about this array you can search for it 
#just like you were searching for itens in an array, like:

fatness_of_the_array-x = x.shape[1] # 1 is refering to the width commented earlier
Posted by: Guest on September-09-2021

Python Answers by Framework

Browse Popular Code Answers by Language