Python Forum
Unable to run array using numpy module - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Unable to run array using numpy module (/thread-17160.html)



Unable to run array using numpy module - vitalstrike82 - Mar-31-2019

I'm starting to learn python. I have install Anaconda package which includes Juypter.

I'm running Jupyter Notebook for python without turning on the Anaconda navigator (Not sure if this impact the compilation of codes). I tried to Create a 3 x 6-dimensional array, containing only float values, but encounter some errors.

In fact, I cannot comprehend what is the error about and would want some advises.

Thanks

import numpy

array2 = numpy.array([[1.0, 2.0, 3.0, 4.0, 5.0, 6.0], [1.1, 2.1, 3.1, 4.1, 5.1, 6.1], [1.2, 2.2, 3.2, 4.2, 5.2, 6.2]])

array2
Error:
AttributeError Traceback (most recent call last) ~\Anaconda3\lib\site-packages\IPython\core\formatters.py in __call__(self, obj) 700 type_pprinters=self.type_printers, 701 deferred_pprinters=self.deferred_printers) --> 702 printer.pretty(obj) 703 printer.flush() 704 return stream.getvalue() ~\Anaconda3\lib\site-packages\IPython\lib\pretty.py in pretty(self, obj) 400 if cls is not object \ 401 and callable(cls.__dict__.get('__repr__')): --> 402 return _repr_pprint(obj, self, cycle) 403 404 return _default_pprint(obj, self, cycle) ~\Anaconda3\lib\site-packages\IPython\lib\pretty.py in _repr_pprint(obj, p, cycle) 695 """A pprint that just redirects to the normal repr function.""" 696 # Find newlines and replace them with p.break_() --> 697 output = repr(obj) 698 for idx,output_line in enumerate(output.splitlines()): 699 if idx: ~\Anaconda3\lib\site-packages\numpy\core\arrayprint.py in array_repr(arr, max_line_width, precision, suppress_small) 1429 elif arr.size > 0 or arr.shape == (0,): 1430 lst = array2string(arr, max_line_width, precision, suppress_small, -> 1431 ', ', prefix, suffix=suffix) 1432 else: # show zero-length shape unless it is (0,) 1433 lst = "[], shape=%s" % (repr(arr.shape),) ~\Anaconda3\lib\site-packages\numpy\core\arrayprint.py in array2string(a, max_line_width, precision, suppress_small, separator, prefix, style, formatter, threshold, edgeitems, sign, floatmode, suffix, **kwarg) 666 return "[]" 667 --> 668 return _array2string(a, options, separator, prefix) 669 670 ~\Anaconda3\lib\site-packages\numpy\core\arrayprint.py in wrapper(self, *args, **kwargs) 458 repr_running.add(key) 459 try: --> 460 return f(self, *args, **kwargs) 461 finally: 462 repr_running.discard(key) ~\Anaconda3\lib\site-packages\numpy\core\arrayprint.py in _array2string(a, options, separator, prefix) 484 485 # find the right formatting function for the array --> 486 format_function = _get_format_function(data, **options) 487 488 # skip over "[" ~\Anaconda3\lib\site-packages\numpy\core\arrayprint.py in _get_format_function(data, **options) 417 return formatdict['longfloat']() 418 else: --> 419 return formatdict['float']() 420 elif issubclass(dtypeobj, _nt.complexfloating): 421 if issubclass(dtypeobj, _nt.clongfloat): ~\Anaconda3\lib\site-packages\numpy\core\arrayprint.py in <lambda>() 356 'int': lambda: IntegerFormat(data), 357 'float': lambda: --> 358 FloatingFormat(data, prec, fmode, supp, sign, legacy=legacy), 359 'longfloat': lambda: 360 FloatingFormat(data, prec, fmode, supp, sign, legacy=legacy), ~\Anaconda3\lib\site-packages\numpy\core\arrayprint.py in __init__(self, data, precision, floatmode, suppress_small, sign, **kwarg) 835 self.large_exponent = False 836 --> 837 self.fillFormat(data) 838 839 def fillFormat(self, data): ~\Anaconda3\lib\site-packages\numpy\core\arrayprint.py in fillFormat(self, data) 844 abs_non_zero = absolute(finite_vals[finite_vals != 0]) 845 if len(abs_non_zero) != 0: --> 846 max_val = np.max(abs_non_zero) 847 min_val = np.min(abs_non_zero) 848 with errstate(over='ignore'): # division can overflow AttributeError: module 'numpy' has no attribute 'max'



RE: Unable to run array using numpy module - micseydel - Mar-31-2019

I just tried
import numpy
numpy.array([[1.0, 2.0, 3.0, 4.0, 5.0, 6.0], [1.1, 2.1, 3.1, 4.1, 5.1, 6.1], [1.2, 2.2, 3.2, 4.2, 5.2, 6.2]])
in Python 2.7 and 3.2 and couldn't reproduce your issue. What versions of the tools are you running? Can you reproduce this outside of Jupyter?


RE: Unable to run array using numpy module - perfringo - Apr-01-2019

I tried in Jupyter Lab and got output:

Output:
array([[1. , 2. , 3. , 4. , 5. , 6. ], [1.1, 2.1, 3.1, 4.1, 5.1, 6.1], [1.2, 2.2, 3.2, 4.2, 5.2, 6.2]])