Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to make a numpy array

>>> x = np.array([2,3,1,0])
>>> x = np.array([2, 3, 1, 0])
>>> x = np.array([[1,2.0],[0,0],(1+1j,3.)]) # note mix of tuple and lists,
    and types
>>> x = np.array([[ 1.+0.j, 2.+0.j], [ 0.+0.j, 0.+0.j], [ 1.+1.j, 3.+0.j]])
Comment

numpy creating arrays

import numpy as np

# create numpy array
arr = np.array([1, 2, 3, 4, 5])
print(type(arr))

# 1d-array
arr = np.array(42)
print(type(arr))

# 2d-array
arr = np.array([[1, 2, 3], [4, 5, 6]])
print(arr)

# 3d-array
arr = np.array([[[1, 2, 3], [4, 5, 6]], [[1, 2, 3], [4, 5, 6]]])
print(arr)

# copy an array any changes make to the copy of the array does not affect the original
arr = np.array([1, 2, 3, 4, 5])
x = arr.copy()
arr[0] = 42

print(arr)
# output [42  2  3  4  5]

print(x)
# output [1 2 3 4 5]

# view an array any changes made to the view will affect the original array
arr = np.array([1, 2, 3, 4, 5])
x = arr.view()
arr[0] = 42

print(arr)
# output [42  2  3  4  5]

print(x)
# output [42  2  3  4  5]
Comment

create array numpy

import numpy as np
a = np.array([1, 2, 3])
Comment

array creation method in numpy

>>> np.arange(10)
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> np.arange(2, 10, dtype=float)
array([ 2., 3., 4., 5., 6., 7., 8., 9.])
>>> np.arange(2, 3, 0.1)
array([ 2. , 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9])
Comment

Array Creation in Numpy

>>> import numpy as np
>>> a = np.array([2, 3, 4])
>>> a
array([2, 3, 4])
>>> a.dtype
dtype('int64')
>>> b = np.array([1.2, 3.5, 5.1])
>>> b.dtype
dtype('float64')
Comment

create array numpy

a = np.array([1, 2, 3, 4, 5, 6])
Comment

PREVIOUS NEXT
Code Example
Python :: python abstract method 
Python :: find an element in pandas 
Python :: python list empty 
Python :: how to use xpath with beautifulsoup 
Python :: python continue 
Python :: how to find total no of nan values in pandas 
Python :: outliers removal pandas 
Python :: python list to string without brackets 
Python :: how to change os path in python 
Python :: plotly heatmap with label 
Python :: df only take 2 columns 
Python :: Dropping NaN in dataframe 
Python :: check missing dates in pandas 
Python :: figsize param in pandas plot 
Python :: date object into date format python 
Python :: python debugger 
Python :: how to get the type of a variable in python 
Python :: replace all missing value with mean pandas 
Python :: genrate unique key in python 
Python :: replace all nan values in dataframe 
Python :: delete rows with value in column pandas 
Python :: pyspark overwrite schema 
Python :: get sum from x to y in python 
Python :: multiple values in python loop for x,y 
Python :: check input in python 
Python :: remove character from string by index in python 
Python :: keras linear regression 
Python :: python os abspath 
Python :: how download youtube video in python 
Python :: how can i make a list of leftovers that are str to make them int in python 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =