Python Forum
Unable to run array using numpy module
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to run array using numpy module
#1
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'
Reply
#2
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?
Reply
#3
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]])
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Convert numpy array to image without loading it into RAM. DreamingInsanity 7 5,728 Feb-08-2024, 09:38 AM
Last Post: paul18fr
  IPython errors for numpy array min/max methods muelaner 1 509 Nov-04-2023, 09:22 PM
Last Post: snippsat
  Expand the range of a NumPy array? PythonNPC 0 707 Jan-31-2023, 02:41 AM
Last Post: PythonNPC
  Change a numpy array to a dataframe Led_Zeppelin 3 1,066 Jan-26-2023, 09:01 PM
Last Post: deanhystad
  from numpy array to csv - rounding SchroedingersLion 6 2,067 Nov-14-2022, 09:09 PM
Last Post: deanhystad
  numpy.array has no attribute head Led_Zeppelin 1 1,193 Jul-13-2022, 12:56 AM
Last Post: Led_Zeppelin
  Seeing al the data in a dataframe or numpy.array Led_Zeppelin 1 1,111 Jul-11-2022, 08:54 PM
Last Post: Larz60+
  go over and search in numpy array faster caro 7 1,693 Jun-20-2022, 04:54 PM
Last Post: deanhystad
  Creating a numpy array from specific values of a spreadsheet column JulianZ 0 1,078 Apr-19-2022, 07:36 AM
Last Post: JulianZ
  Trying to understand Numpy/array nabuchadresar 2 1,793 Dec-17-2021, 07:52 AM
Last Post: nabuchadresar

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020