You are on page 1of 7

TypeError: randint() got an unexpected keyword argument 'ndmin'

In [62]: z=np.random.randint(1,5, (3,3))

In [63]: np.array(z,ndmin =6)


Out[63]:
array([[[[[[4, 1, 1],
[1, 3, 3],
[2, 3, 4]]]]]])

In [64]: p={"col_1":[{"n1":5},{"n2":6}], "col_2":[{"n1":9},{"n2":10}]}

In [65]: import pandas as pd

In [66]: pd.DataFrame(p)
Out[66]:
col_1 col_2
0 {u'n1': 5} {u'n1': 9}
1 {u'n2': 6} {u'n2': 10}

In [67]: pd.DataFrame(p)
Out[67]:
col_1 col_2
0 {u'n1': 5} {u'n1': 9}
1 {u'n2': 6} {u'n2': 10}

In [68]: np.array((5,5))
Out[68]: array([5, 5])

In [69]: np.random.randint((4,4))

TypeErrorTraceback (most recent call last)


<ipython-input-69-b9161d72f013> in <module>()
----> 1 np.random.randint((4,4))

mtrand.pyx in mtrand.RandomState.randint()

TypeError: int() argument must be a string or a number, not 'tuple'

In [70]: np.random.randint(1,100,(4,4))
Out[70]:
array([[13, 1, 76, 14],
[21, 55, 98, 93],
[88, 74, 88, 66],
[91, 41, 49, 45]])

In [71]: np.random((3,4))

TypeErrorTraceback (most recent call last)


<ipython-input-71-cfe52906aecb> in <module>()
----> 1 np.random((3,4))

TypeError: 'module' object is not callable

In [72]: np.random.random((3,3))
Out[72]:
array([[0.62880183, 0.24702432, 0.13784995],
[0.51472655, 0.77375286, 0.82740054],
[0.90100416, 0.16905432, 0.48120537]])

In [73]: A= np.random.randint(1,100,(4,4))

In [74]: A
Out[74]:
array([[55, 23, 92, 55],
[20, 30, 26, 44],
[37, 42, 52, 82],
[54, 82, 75, 19]])

In [75]: A.copy()
Out[75]:
array([[55, 23, 92, 55],
[20, 30, 26, 44],
[37, 42, 52, 82],
[54, 82, 75, 19]])

In [76]: Z = A

In [77]: Z
Out[77]:
array([[55, 23, 92, 55],
[20, 30, 26, 44],
[37, 42, 52, 82],
[54, 82, 75, 19]])

In [78]: np.sort(Z)
Out[78]:
array([[23, 55, 55, 92],
[20, 26, 30, 44],
[37, 42, 52, 82],
[19, 54, 75, 82]])

In [79]: help(np.sort)
Help on function sort in module numpy.core.fromnumeric:

sort(a, axis=-1, kind='quicksort', order=None)


Return a sorted copy of an array.

Parameters
----------
a : array_like
Array to be sorted.
axis : int or None, optional
Axis along which to sort. If None, the array is flattened before
sorting. The default is -1, which sorts along the last axis.
kind : {'quicksort', 'mergesort', 'heapsort'}, optional
Sorting algorithm. Default is 'quicksort'.
order : str or list of str, optional
When `a` is an array with fields defined, this argument specifies
which fields to compare first, second, etc. A single field can
be specified as a string, and not all fields need be specified,
but unspecified fields will still be used, in the order in which
they come up in the dtype, to break ties.

Returns
-------
sorted_array : ndarray
Array of the same type and shape as `a`.

See Also
--------
ndarray.sort : Method to sort an array in-place.
argsort : Indirect sort.
lexsort : Indirect stable sort on multiple keys.
searchsorted : Find elements in a sorted array.
partition : Partial sort.

Notes
-----
The various sorting algorithms are characterized by their average speed,
worst case performance, work space size, and whether they are stable. A
stable sort keeps items with the same key in the same relative
order. The three available algorithms have the following
properties:

=========== ======= ============= ============ =======


kind speed worst case work space stable
=========== ======= ============= ============ =======
'quicksort' 1 O(n^2) 0 no
'mergesort' 2 O(n*log(n)) ~n/2 yes
'heapsort' 3 O(n*log(n)) 0 no
=========== ======= ============= ============ =======

All the sort algorithms make temporary copies of the data when
sorting along any but the last axis. Consequently, sorting along
the last axis is faster and uses less space than sorting along
any other axis.
The sort order for complex numbers is lexicographic. If both the real
and imaginary parts are non-nan then the order is determined by the
real parts except when they are equal, in which case the order is
determined by the imaginary parts.

Previous to numpy 1.4.0 sorting real and complex arrays containing nan
values led to undefined behaviour. In numpy versions >= 1.4.0 nan
values are sorted to the end. The extended sort order is:

* Real: [R, nan]


* Complex: [R + Rj, R + nanj, nan + Rj, nan + nanj]

where R is a non-nan real value. Complex values with the same nan
placements are sorted according to the non-nan part if it exists.
Non-nan values are sorted as before.

.. versionadded:: 1.12.0

quicksort has been changed to an introsort which will switch


heapsort when it does not make enough progress. This makes its
worst case O(n*log(n)).

Examples
--------
>>> a = np.array([[1,4],[3,1]])
>>> np.sort(a) # sort along the last axis
array([[1, 4],
[1, 3]])
>>> np.sort(a, axis=None) # sort the flattened array
array([1, 1, 3, 4])
>>> np.sort(a, axis=0) # sort along the first axis
array([[1, 1],
[3, 4]])

Use the `order` keyword to specify a field to use when sorting a


structured array:

>>> dtype = [('name', 'S10'), ('height', float), ('age', int)]


>>> values = [('Arthur', 1.8, 41), ('Lancelot', 1.9, 38),
... ('Galahad', 1.7, 38)]
>>> a = np.array(values, dtype=dtype) # create a structured array
>>> np.sort(a, order='height') # doctest: +SKIP
array([('Galahad', 1.7, 38), ('Arthur', 1.8, 41),
('Lancelot', 1.8999999999999999, 38)],
dtype=[('name', '|S10'), ('height', '<f8'), ('age', '<i4')])

Sort by age, then height if ages are equal:

>>> np.sort(a, order=['age', 'height']) # doctest: +SKIP


array([('Galahad', 1.7, 38), ('Lancelot', 1.8999999999999999, 38),
('Arthur', 1.8, 41)],
dtype=[('name', '|S10'), ('height', '<f8'), ('age', '<i4')])

In [80]: Z
Out[80]:
array([[55, 23, 92, 55],
[20, 30, 26, 44],
[37, 42, 52, 82],
[54, 82, 75, 19]])

In [81]: np.sort(z,axis = 1)
Out[81]:
array([[1, 1, 4],
[1, 3, 3],
[2, 3, 4]])

In [82]: np.sort(Z,axis = 1)
Out[82]:
array([[23, 55, 55, 92],
[20, 26, 30, 44],
[37, 42, 52, 82],
[19, 54, 75, 82]])

In [83]: np.sort(Z, sort =0)

TypeErrorTraceback (most recent call last)


<ipython-input-83-3b6437c2f6ec> in <module>()
----> 1 np.sort(Z, sort =0)

TypeError: sort() got an unexpected keyword argument 'sort'

In [84]: np.sort(Z, axis =1)


Out[84]:
array([[23, 55, 55, 92],
[20, 26, 30, 44],
[37, 42, 52, 82],
[19, 54, 75, 82]])

In [85]: np.sort(Z, axis =0)


Out[85]:
array([[20, 23, 26, 19],
[37, 30, 52, 44],
[54, 42, 75, 55],
[55, 82, 92, 82]])

In [86]: x = np.random.random([3,3])

In [87]: x
Out[87]:
array([[0.8016841 , 0.12227096, 0.65451371],
[0.2947682 , 0.88168101, 0.11115688],
[0.5604033 , 0.54275188, 0.65132816]])

In [88]: x = np.random.random([2,3])

In [89]: x
Out[89]:
array([[0.56574296, 0.96400087, 0.59604626],
[0.61267651, 0.99812334, 0.95208975]])

In [90]: p = np.matrix(x)

In [91]: p
Out[91]:
matrix([[0.56574296, 0.96400087, 0.59604626],
[0.61267651, 0.99812334, 0.95208975]])

In [92]: x
Out[92]:
array([[0.56574296, 0.96400087, 0.59604626],
[0.61267651, 0.99812334, 0.95208975]])

In [93]: x.shape()

TypeErrorTraceback (most recent call last)


<ipython-input-93-15bbc2c5eb7d> in <module>()
----> 1 x.shape()

TypeError: 'tuple' object is not callable

In [94]: x.shape
Out[94]: (2L, 3L)

In [95]: len(x)
Out[95]: 2

In [96]: x.dim
AttributeErrorTraceback (most recent call last)
<ipython-input-96-d19b20e12c3e> in <module>()
----> 1 x.dim

AttributeError: 'numpy.ndarray' object has no attribute 'dim'

In [97]: x.ndim
Out[97]: 2

In [98]: x.resize((3,2))

In [99]: x
Out[99]:
array([[0.56574296, 0.96400087],
[0.59604626, 0.61267651],
[0.99812334, 0.95208975]])

In [100]: x.reshape()

TypeErrorTraceback (most recent call last)


<ipython-input-100-de5beb936362> in <module>()
----> 1 x.reshape()

TypeError: reshape() takes exactly 1 argument (0 given)

In [101]: x.reshape((3,2))
Out[101]:
array([[0.56574296, 0.96400087],
[0.59604626, 0.61267651],
[0.99812334, 0.95208975]])

In [102]: x.flatten()
Out[102]:
array([0.56574296, 0.96400087, 0.59604626, 0.61267651, 0.99812334,
0.95208975])

In [103]: x.flatten()
Out[103]:
array([0.56574296, 0.96400087, 0.59604626, 0.61267651, 0.99812334,
0.95208975])

In [104]: x.flatten().resize(2,3\)
File "<ipython-input-104-95fa8b2ca2b1>", line 1
x.flatten().resize(2,3\)
^
SyntaxError: unexpected character after line continuation character

In [105]: x.flatten().resize(2,3)

In [106]: x
Out[106]:
array([[0.56574296, 0.96400087],
[0.59604626, 0.61267651],
[0.99812334, 0.95208975]])

In [107]: x
Out[107]:
array([[0.56574296, 0.96400087],
[0.59604626, 0.61267651],
[0.99812334, 0.95208975]])

In [108]: x.reshape(3,2)
Out[108]:
array([[0.56574296, 0.96400087],
[0.59604626, 0.61267651],
[0.99812334, 0.95208975]])

In [109]: x.reshape((3,2))
Out[109]:
array([[0.56574296, 0.96400087],
[0.59604626, 0.61267651],
[0.99812334, 0.95208975]])

In [110]: z = np.random.randint((5,5))

TypeErrorTraceback (most recent call last)


<ipython-input-110-45e6754c9006> in <module>()
----> 1 z = np.random.randint((5,5))

mtrand.pyx in mtrand.RandomState.randint()

TypeError: int() argument must be a string or a number, not 'tuple'

In [111]: z = np.random.randint(1,100,(5,5))

In [112]: z
Out[112]:
array([[39, 7, 73, 62, 24],
[86, 63, 33, 67, 45],
[68, 59, 23, 49, 14],
[20, 44, 60, 5, 85],
[ 6, 29, 12, 70, 32]])

In [113]: z[0,0]
Out[113]: 39

In [114]: z[2,4]
Out[114]: 14

In [115]: z[0,3]
Out[115]: 62

In [116]: z[1,3]
Out[116]: 67

In [117]: z[0:1,1:2]
Out[117]: array([[7]])

In [118]: z[0:2,1:3]
Out[118]:
array([[ 7, 73],
[63, 33]])

In [119]: z = linspace(1:2:12)
File "<ipython-input-119-061d0f1205f4>", line 1
z = linspace(1:2:12)
^
SyntaxError: invalid syntax

In [120]: z = linspace(1,12,3)

NameErrorTraceback (most recent call last)


<ipython-input-120-a9f2df633077> in <module>()
----> 1 z = linspace(1,12,3)

NameError: name 'linspace' is not defined

In [121]: z = np.linspace(1,12,3)

In [122]: z
Out[122]: array([ 1. , 6.5, 12. ])

In [123]: z
Out[123]: array([ 1. , 6.5, 12. ])

In [124]: y = np.random.randomint(1,100,(4,5))

AttributeErrorTraceback (most recent call last)


<ipython-input-124-47101113e631> in <module>()
----> 1 y = np.random.randomint(1,100,(4,5))

AttributeError: 'module' object has no attribute 'randomint'

In [125]: y = np.random.randint(1,100,(4,5))

In [126]: y
Out[126]:
array([[58, 11, 82, 38, 62],
[98, 21, 45, 50, 57],
[72, 5, 73, 39, 79],
[ 3, 44, 13, 61, 29]])

In [127]: np.apply_along_axis(lamda x:x+100,0,y)


File "<ipython-input-127-adece6b911a8>", line 1
np.apply_along_axis(lamda x:x+100,0,y)
^
SyntaxError: invalid syntax

In [128]: np.apply_along_axis(lambda x:x+100,0,y)


Out[128]:
array([[158, 111, 182, 138, 162],
[198, 121, 145, 150, 157],
[172, 105, 173, 139, 179],
[103, 144, 113, 161, 129]])

In [129]: np.apply_along_axis(lambda x:x+200,2,y)

AxisErrorTraceback (most recent call last)


<ipython-input-129-0759f0532e4c> in <module>()
----> 1 np.apply_along_axis(lambda x:x+200,2,y)

C:\ProgramData\Anaconda2\lib\site-packages\numpy\lib\shape_base.pyc in apply_along_axis(func1d, axis, arr, *args,


**kwargs)
114 arr = asanyarray(arr)
115 nd = arr.ndim
--> 116 axis = normalize_axis_index(axis, nd)
117
118 # arr, with the iteration axis at the end

AxisError: axis 2 is out of bounds for array of dimension 2

In [130]: np.apply_along_axis(lambda x:x+200,1,y)


Out[130]:
array([[258, 211, 282, 238, 262],
[298, 221, 245, 250, 257],
[272, 205, 273, 239, 279],
[203, 244, 213, 261, 229]])

In [131]: np.apply_along_axis(lambda x:x+200,1,y[0:2,])


Out[131]:
array([[258, 211, 282, 238, 262],
[298, 221, 245, 250, 257]])

In [132]: y[0,2,]=np.apply_along_axis(lambda x:x+200,1,y[0:2,])

ValueErrorTraceback (most recent call last)


<ipython-input-132-4afe42118633> in <module>()
----> 1 y[0,2,]=np.apply_along_axis(lambda x:x+200,1,y[0:2,])

ValueError: setting an array element with a sequence.

In [133]: y[0:2,]=np.apply_along_axis(lambda x:x+200,1,y[0:2,])

In [134]: y
Out[134]:
array([[258, 211, 282, 238, 262],
[298, 221, 245, 250, 257],
[ 72, 5, 73, 39, 79],
[ 3, 44, 13, 61, 29]])

You might also like