Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Array in numpy
I installed modul numpy and wrote this code:

import numpy as np
height = [ 1.73, 1.68, 1.71, 1.89, 1.79]
weight = [ 65.4, 59.2, 63.6, 88.4, 68.7]

np_height = np.array(height)
np_weight = np.array(weight)

result = np_weigh / np_height ** 2
I receive message "Attribute error: modul 'numpy' has no attribute 'array'
Don't see how is this possible.
Look if have you have named a file
Here how it look if it work,__file__ will show placement.
>>> import numpy as np
>>> np.__file__
>>> np.array
<built-in function array> 
micseydel likes this post
Yes, I named my file, not sure that I understand the rest.
Rename the file eg to
What happenes is when file is in Python search path,
Python will try to import it.
So when do import numpy as np it is in fact using your file and not the numpy package.
Truman likes this post
I renamed the file we are talking about above, to
I run >>> import numpy as np
I run >>> np.__file__ 'C:\Adrian\Python37\Lib\numpy-1.11.2\numpy\'
SyntaxError: invalid syntax
what should my last command be for there to be no error? It worked once, I don't remember how I did it.
(May-26-2019, 03:25 AM)aapurdel Wrote: I renamed the file we are talking about above, to
This is and old Thread,and no you should not at all rename to
This was about that naming a fie yourself to,then it shadow the real in library.
So here it was only talked about rename make that name yourself) to a other name eg

Quote:I run >>> np.__file__ 'C:\Adrian\Python37\Lib\numpy-1.11.2\numpy\'
You have the return value that should not be there.
>>> import numpy as np

>>> np.__file__ # Nothing here

# If work then it work
>>> np.arange(10, 30, 5)
array([10, 15, 20, 25])

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Numpy structured array Nitram 3 181 Sep-17-2019, 10:09 PM
Last Post: jefsummers
  numpy.copy / numpy.delete paul18fr 3 236 Jul-26-2019, 01:51 PM
Last Post: paul18fr
  AttributeError: module 'numpy' has no attribute 'array aapurdel 7 3,045 May-29-2019, 02:48 AM
Last Post: heiner55
  [split] Array in numpy aapurdel 1 258 May-25-2019, 08:05 PM
Last Post: buran
  [numpy]add a value to an array elmismo999 1 328 May-23-2019, 04:15 PM
Last Post: michalmonday
  "erlarge" a numpy-matrix to numpy-array PhysChem 2 368 Apr-09-2019, 04:54 PM
Last Post: PhysChem
  while creating a array using numpy.arrange, how to negate only the last 50 numbers? vicky53 1 369 Apr-06-2019, 11:52 AM
Last Post: scidam
  How to get the size of a numpy array? mcgrim 2 426 Mar-23-2019, 02:25 PM
Last Post: perfringo
  creating an empty NumPy array in Python sandeepatel 2 900 Jan-16-2019, 09:24 AM
Last Post: rinu
  Dictionary or Numpy Array? jarrod0987 2 1,135 Oct-05-2018, 06:48 PM
Last Post: jarrod0987

Forum Jump:

Users browsing this thread: 1 Guest(s)