[go: up one dir, main page]

0% found this document useful (0 votes)
76 views11 pages

Python Odt

The document shows examples of using NumPy to create arrays and manipulate them. It demonstrates creating zero and one arrays of different sizes and shapes. Errors are displayed when trying to create arrays that are too large or the wrong data type. Dimension, shape and data type properties of arrays are accessed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views11 pages

Python Odt

The document shows examples of using NumPy to create arrays and manipulate them. It demonstrates creating zero and one arrays of different sizes and shapes. Errors are displayed when trying to create arrays that are too large or the wrong data type. Dimension, shape and data type properties of arrays are accessed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 11

Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.

1914 64 bit (AMD64)] on win32


Type "help", "copyright", "credits" or "license" for more information.
>>> a=np.zeros(10000000000000000000000000000000000000000);
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'np' is not defined
>>> import numpy
>>> import numpy as np
>>>
a=np.zeros(1000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000);
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Maximum allowed dimension exceeded
>>> import numpy
>>> import numpy as np
>>> a=np.zeros(10000000000000000000000000);
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Maximum allowed dimension exceeded
>>> import numpy
>>> import numpy as np
>>> a=np.zeros(100)
>>> print(a)
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0.]
>>> import numpy
>>> import numpy as np
>>> a=np.zeros(10000000000000000000000000)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Maximum allowed dimension exceeded
>>> import numpy
>>> import numpy as np
>>> a=np.zeros(1000000)
>>> print(a)
[0. 0. 0. ... 0. 0. 0.]
>>>
>>> import numpy
>>> import numpy as np
>>> a=np.zeros(10)
>>> print(a)
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
>>> a=np.ones((3.5))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-
packages\numpy\core\numeric.py", line 214, in ones
a = empty(shape, dtype, order)
TypeError: 'float' object cannot be interpreted as an integer
>>> import numpy
>>> import numpy as np
>>> a=np.zeros(10)
>>> print(a)
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
>>> a=np.ones((3,5))
>>> print(a)
[[1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1.]]
>>> b=np.random.random(n,p)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'n' is not defined
>>> b=np.random.random((n,p))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'n' is not defined
>>> b=np.random.random((10,6))
>>> print(b)
[[0.35257275 0.32296699 0.51984835 0.08770574 0.04407852 0.35110023]
[0.22433435 0.42057711 0.1479866 0.64155896 0.88667609 0.06790612]
[0.33069882 0.92702505 0.09229457 0.68200493 0.87323083 0.33445378]
[0.15178406 0.67196376 0.80489324 0.52189508 0.10871881 0.71228479]
[0.80149702 0.32834188 0.75176388 0.30463832 0.53406896 0.62356764]
[0.55575943 0.48897693 0.94854444 0.15923746 0.70751191 0.38721151]
[0.41661593 0.69932249 0.73896406 0.17249266 0.62014601 0.04286307]
[0.35789231 0.74350964 0.93755722 0.6252757 0.44183373 0.48135926]
[0.98960936 0.76333755 0.07163889 0.55720754 0.29800684 0.59554266]
[0.9610097 0.65719303 0.23529205 0.85266744 0.67933991 0.30871019]]
>>> b=np.random.random((1000,1000)
... print(b)
File "<stdin>", line 2
print(b)
^
SyntaxError: invalid syntax
>>> b=np.random.random((1000,1000))
>>> print(b)
[[0.55466673 0.84734562 0.95444528 ... 0.97437002 0.07222946 0.54465875]
[0.82735726 0.39776748 0.4918792 ... 0.20566623 0.67737375 0.68845618]
[0.32702473 0.40282174 0.46926498 ... 0.93308579 0.29796356 0.89745051]
...
[0.20978533 0.51622712 0.1258048 ... 0.86817524 0.06414936 0.10001336]
[0.30113072 0.36226945 0.11626711 ... 0.27371377 0.00843559 0.68622503]
[0.73846636 0.69155175 0.95657832 ... 0.85132579 0.96473354 0.9641714 ]]
>>> c=np.diag(4)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<__array_function__ internals>", line 6, in diag
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-
packages\numpy\lib\twodim_base.py", line 285, in diag
raise ValueError("Input must be 1- or 2-d.")
ValueError: Input must be 1- or 2-d.
>>> c=np.diag(1000)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<__array_function__ internals>", line 6, in diag
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-
packages\numpy\lib\twodim_base.py", line 285, in diag
raise ValueError("Input must be 1- or 2-d.")
ValueError: Input must be 1- or 2-d.
>>> b=np.random.random((10,6))
>>> print(b)
[[0.35295208 0.55097982 0.47642886 0.52961717 0.92411347 0.33831769]
[0.16409809 0.59604352 0.92972753 0.88630066 0.95300319 0.39677695]
[0.23280953 0.37777578 0.1298155 0.33086163 0.46130391 0.02320919]
[0.0636056 0.59464341 0.90945756 0.00586479 0.32528756 0.19203672]
[0.26718905 0.30128208 0.8754593 0.16069494 0.6575034 0.86574308]
[0.96089705 0.60218409 0.42161578 0.45622075 0.32859432 0.47510767]
[0.49515136 0.40565522 0.79754362 0.10532545 0.04618959 0.94563858]
[0.39837294 0.76843382 0.27884217 0.66617953 0.64554273 0.27159011]
[0.7331472 0.82671482 0.9796391 0.01604185 0.78007529 0.9083047 ]
[0.88612285 0.44886546 0.98035478 0.77456234 0.52629568 0.1134331 ]]
>>> c=np.diag(10)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<__array_function__ internals>", line 6, in diag
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-
packages\numpy\lib\twodim_base.py", line 285, in diag
raise ValueError("Input must be 1- or 2-d.")
ValueError: Input must be 1- or 2-d.
>>> c=np.diag(3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<__array_function__ internals>", line 6, in diag
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-
packages\numpy\lib\twodim_base.py", line 285, in diag
raise ValueError("Input must be 1- or 2-d.")
ValueError: Input must be 1- or 2-d.
>>> c=np.diag((10))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<__array_function__ internals>", line 6, in diag
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-
packages\numpy\lib\twodim_base.py", line 285, in diag
raise ValueError("Input must be 1- or 2-d.")
ValueError: Input must be 1- or 2-d.
>>> b=np.random.random((10,10))
>>> print(b)
[[0.5469292 0.48962989 0.9952635 0.19470311 0.53480969 0.2788267
0.22661985 0.70116142 0.56253442 0.71857179]
[0.80945705 0.37141022 0.96173827 0.99345606 0.5658962 0.77458396
0.9331145 0.07461708 0.69627254 0.97442656]
[0.93268006 0.59363423 0.11214948 0.73854435 0.5529986 0.70764639
0.85759033 0.8712764 0.91566187 0.20614464]
[0.68208987 0.55502452 0.80014881 0.27298833 0.91360328 0.94181494
0.69095983 0.55524458 0.50768459 0.06765636]
[0.15591738 0.82927593 0.11901259 0.86058324 0.94459921 0.45899976
0.68893382 0.05663718 0.46257749 0.25506183]
[0.82343755 0.63016698 0.74537749 0.88311501 0.68661804 0.53961783
0.21790594 0.30570745 0.2152454 0.94247325]
[0.07807972 0.52382315 0.20477746 0.75189174 0.97581017 0.7176599
0.78928287 0.00192736 0.44419311 0.60115712]
[0.84006096 0.84292036 0.40723444 0.10233397 0.27692305 0.39032849
0.4435727 0.08311712 0.84682835 0.28950974]
[0.76372568 0.933491 0.95155558 0.0753219 0.43821083 0.16139363
0.78006769 0.78830705 0.88682442 0.79532138]
[0.14794825 0.54676118 0.02580333 0.44604639 0.63269163 0.63335286
0.40085743 0.64977882 0.6133875 0.31785658]]
>>> c=np.diag(10)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<__array_function__ internals>", line 6, in diag
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-
packages\numpy\lib\twodim_base.py", line 285, in diag
raise ValueError("Input must be 1- or 2-d.")
ValueError: Input must be 1- or 2-d.
>>> import numpy
>>> import numpy as np
>>> a=np.zeros(10)
>>> print(a)
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
>>> a.ndim
1
>>> a.shape
(10,)
>>> a.dtype
dtype('float64')
>>> a=np.zeros(10);
>>> print(a)
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
>>> a=np.ones((3,5)int)
File "<stdin>", line 1
a=np.ones((3,5)int)
^
SyntaxError: invalid syntax
>>> import numpy
>>> import numpy as np
>>> a=np.zeros(10)
>>> print(a)
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
>>> a.ndim
1
>>> a.shape
(10,)
>>> a.dtype
dtype('float64')
>>> a=np.zeros(10);
>>> print(a)
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
>>> a=np.ones((3,5)int))
File "<stdin>", line 1
a=np.ones((3,5)int))
^
SyntaxError: invalid syntax
>>> import numpy
>>> import numpy as np
>>> a=np.zeros(10)
>>> print(a)
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
>>> a.ndim
1
>>> a.shape
(10,)
>>> a.dtype
dtype('float64')
>>> a=np.zeros(10);
>>> print(a)
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
>>> a=np.ones((3,5),int))
File "<stdin>", line 1
a=np.ones((3,5),int))
^
SyntaxError: invalid syntax
>>> import numpy
>>> import numpy as np
>>> a=np.zeros(10)
>>> print(a)
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
>>> a.ndim
1
>>> a.shape
(10,)
>>> a.dtype
dtype('float64')
>>> a=np.zeros(10);
>>> print(a)
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
>>> a=np.ones(3,5)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-
packages\numpy\core\numeric.py", line 214, in ones
a = empty(shape, dtype, order)
TypeError: data type not understood
>>> a=np.ones(3,5)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-
packages\numpy\core\numeric.py", line 214, in ones
a = empty(shape, dtype, order)
TypeError: data type not understood
>>> a=np(3,5);
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable
>>> import numpy
>>> import numpy as np
>>> a=np.zeros(10)
>>> print(a)
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
>>> a.ndim
1
>>> a.shape
(10,)
>>> a.dtype
dtype('float64')
>>> a=np.ones((3,5))
>>> print(a)
[[1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1.]]
>>> b=np.random.random((3,5))
>>> print(b)
[[0.3939453 0.34933165 0.57175756 0.02278868 0.46867386]
[0.87769797 0.17895454 0.13148888 0.16649767 0.78875245]
[0.91008706 0.53233731 0.50215049 0.65702611 0.61958417]]
>>> c=np.diag(3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<__array_function__ internals>", line 6, in diag
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-
packages\numpy\lib\twodim_base.py", line 285, in diag
raise ValueError("Input must be 1- or 2-d.")
ValueError: Input must be 1- or 2-d.
>>> import numpy
>>> import numpy as np
>>> a=np.zeros(10)
>>> print(a)
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
>>> a.ndim
1
>>> a.shape
(10,)
>>> a.dtype
dtype('float64')
>>> a=np.ones((3,5))
>>> print(a)
[[1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1.]]
>>> b=np.random.random((3,5))
>>> print(b)
[[0.95875914 0.89800711 0.59228403 0.90604254 0.48518558]
[0.73710552 0.60948923 0.0628504 0.54169655 0.63775469]
[0.92322451 0.12871565 0.55343673 0.48654731 0.07649418]]
>>> c=np.diag((3))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<__array_function__ internals>", line 6, in diag
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-
packages\numpy\lib\twodim_base.py", line 285, in diag
raise ValueError("Input must be 1- or 2-d.")
ValueError: Input must be 1- or 2-d.
>>> import numpy
>>> import numpy as np
>>> a=np.zeros(10)
>>> print(a)
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
>>> a.ndim
1
>>> a.shape
(10,)
>>> a.dtype
dtype('float64')
>>> a=np.ones((3,5))
>>> print(a)
[[1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1.]]
>>> b=np.random.random((3,5))
>>> print(b)
[[0.79908496 0.17129964 0.47639875 0.75123301 0.38500832]
[0.03012696 0.79925784 0.43061113 0.49376196 0.98321508]
[0.96443987 0.68258096 0.13708962 0.01715879 0.43878307]]
>>> c=np.diag((1))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<__array_function__ internals>", line 6, in diag
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-
packages\numpy\lib\twodim_base.py", line 285, in diag
raise ValueError("Input must be 1- or 2-d.")
ValueError: Input must be 1- or 2-d.
>>> import numpy
>>> import numpy as np
>>> a=np.zeros(10)
>>> print(a)
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
>>> a.ndim
1
>>> a.shape
(10,)
>>> a.dtype
dtype('float64')
>>> a=np.ones((3,5))
>>> print(a)
[[1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1.]]
>>> b=np.random.random((3,5))
>>> print(b)
[[0.50454447 0.27541379 0.11220525 0.13732729 0.51228541]
[0.16075636 0.28446861 0.96670369 0.25262511 0.59873016]
[0.94722788 0.99639859 0.0765779 0.33835075 0.29767329]]
>>> c=np.diag((a))
>>> print(c)
[1. 1. 1.]
>>> d=c.copy()
>>> print(d)
[1. 1. 1.]
>>> a=np.array([1,2,3,4,5,6,7,8,9,10])
>>> print(a)
[ 1 2 3 4 5 6 7 8 9 10]
>>> print(a[1/])
File "<stdin>", line 1
print(a[1/])
^
SyntaxError: invalid syntax
>>> import numpy
>>> import numpy as np
>>> a=np.zeros(10)
>>> print(a)
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
>>> a.ndim
1
>>> a.shape
(10,)
>>> a.dtype
dtype('float64')
>>> a=np.ones((3,5))
>>> print(a)
[[1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1.]]
>>> b=np.random.random((3,5))
>>> print(b)
[[0.36838964 0.31090442 0.80314625 0.62200482 0.79678655]
[0.47493818 0.04655059 0.02447731 0.00616273 0.26497252]
[0.48769318 0.15380076 0.08287923 0.62554192 0.27908196]]
>>> c=np.diag((1))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<__array_function__ internals>", line 6, in diag
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-
packages\numpy\lib\twodim_base.py", line 285, in diag
raise ValueError("Input must be 1- or 2-d.")
ValueError: Input must be 1- or 2-d.
>>> import numpy
>>> import numpy as np
>>> a=np.zeros(10)
>>> print(a)
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
>>> a.ndim
1
>>> a.shape
(10,)
>>> a.dtype
dtype('float64')
>>> a=np.ones((3,5))
>>> print(a)
[[1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1.]]
>>> b=np.random.random((3,5))
>>> print(b)
[[0.30725085 0.50931339 0.06520068 0.89285467 0.95111718]
[0.32118148 0.58908177 0.96803351 0.18756156 0.9704963 ]
[0.02102689 0.56201599 0.03252955 0.38073019 0.37646038]]
>>> c=np.diag((a))
>>> print(c)
[1. 1. 1.]
>>> d=c.copy()
>>> print(d)
[1. 1. 1.]
>>> a=np.array([1,2,3,4,5,6,7,8,9,10])
>>> print(a)
[ 1 2 3 4 5 6 7 8 9 10]
>>> print(a[1:])
[ 2 3 4 5 6 7 8 9 10]
>>> print(a[:3])
[1 2 3]
>>> print(a[3:7])
[4 5 6 7]
>>> a=[[2,3,5,1,0,1,0,12,8],[4,9,78,4,6,42,1,4,7]]
>>> a=[[4,8,7,4,7,5,7,6,9],[4,9,78,5,6,3,6,7,9]]
>>>
>>> a=[[2,3,5,1,0,1,0,12,8],[4,9,78,4,6,42,1,4,7]]
>>> b=[[4,8,7,4,7,5,7,6,9],[4,9,78,5,6,3,6,7,9]]
>>> c=dot(a,b)*
File "<stdin>", line 1
c=dot(a,b)*
^
SyntaxError: invalid syntax
>>> a=[[2,3,5,1,0,1,0,12,8],[4,9,78,4,6,42,1,4,7]]
>>> b=[[4,8,7,4,7,5,7,6,9],[4,9,78,5,6,3,6,7,9]]
>>> np.dot(a,b)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<__array_function__ internals>", line 6, in dot
ValueError: shapes (2,9) and (2,9) not aligned: 9 (dim 1) != 2 (dim 0)
>>> a=[[2,3,5,1,0,1,0,12,8],[4,9,78,4,6,42,1,4,7]]
>>> b=[[4,8,7,4,7,5,7,6,9],[4,9,78,5,6,3,6,7,9]]
>>> np.dot((a,b))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<__array_function__ internals>", line 4, in dot
TypeError: dot() missing 1 required positional argument: 'b'
>>> a=[[2,3,5,1,0,1,0,12,8],[4,9,78,4,6,42,1,4,7]]
>>> b=[[4,8,7,4,7,5,7,6,9],[4,9,78,5,6,3,6,7,9]]
>>> c=dot(a,b)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'dot' is not defined
>>> a=[[4,5,9],[7,6,4]]
>>> print(np.sum(a))
35
>>> print(np.prod(a))
30240
>>> np.transpose(a)
array([[4, 7],
[5, 6],
[9, 4]])
>>>
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import numpy as np
>>> a=np.array[[8,3,2],[5,1,6]]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'builtin_function_or_method' object is not subscriptable
>>> import numpy
>>> import numpy as np
>>> a=np.arrag[[8,3,2],[5,1,6]]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'numpy' has no attribute 'arrag'
>>> import numpy
>>> import numpy as np
>>> a=np.arrag([[8,3,2],[5,1,6]])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'numpy' has no attribute 'arrag'
>>> import numpy
>>> import numpy as np
>>> a=np.array([[8,3,2],[5,1,6]])
>>> print(a)
[[8 3 2]
[5 1 6]]
>>> a.ndim
2
>>> a.shape
(2, 3)
>>> a.dtype
dtype('int32')

You might also like