Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Array in numpy
#1
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
print(result)
I receive message "Attribute error: modul 'numpy' has no attribute 'array'
Don't see how is this possible.
Quote
#2
Look if have you have named a file numpy.py.
Here how it look if it work,__file__ will show placement.
>>> import numpy as np
>>> np.__file__
'C:\\Python36\\lib\\site-packages\\numpy\\__init__.py'
>>> np.array
<built-in function array> 
micseydel likes this post
Quote
#3
Yes, I named my file numpy.py, not sure that I understand the rest.
Quote
#4
Rename the file eg to my_numpy.py.
What happenes is when nupmy.py 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 numpy.py file and not the numpy package.
Truman likes this post
Quote
#5
I renamed the file we are talking about above, __init__.py to numpy.py
I run >>> import numpy as np
I run >>> np.__file__ 'C:\Adrian\Python37\Lib\numpy-1.11.2\numpy\numpy.py'
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.
Quote
#6
(May-26-2019, 03:25 AM)aapurdel Wrote: I renamed the file we are talking about above, __init__.py to numpy.py
This is and old Thread,and no you should not at all rename __init__.py to numpy.py
This was about that naming a fie yourself to numpy.py,then it shadow the real numpy.py in library.
So here it was only talked about rename numpy.py(if make that name yourself) to a other name eg my_numpycode.py.

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

>>> np.__file__ # Nothing here
'C:\\python37\\lib\\site-packages\\numpy\\__init__.py'

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

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  converting dataframe to int numpy array glennford49 1 296 Apr-04-2020, 06:15 AM
Last Post: snippsat
  Replacing sub array in Numpy array ThemePark 5 381 Apr-01-2020, 01:16 PM
Last Post: ThemePark
  How to prepare a NumPy array which include float type array elements subhash 0 260 Mar-02-2020, 06:46 AM
Last Post: subhash
  numpy.where array search for string in just one coordinate adetheheat 1 401 Jan-09-2020, 07:09 PM
Last Post: paul18fr
  memory issue loading movie to numpy array djf123 1 328 Nov-07-2019, 06:19 AM
Last Post: ThomasL
  Numpy structured array Nitram 3 627 Sep-17-2019, 10:09 PM
Last Post: jefsummers
  numpy.copy / numpy.delete paul18fr 3 691 Jul-26-2019, 01:51 PM
Last Post: paul18fr
  AttributeError: module 'numpy' has no attribute 'array aapurdel 7 13,562 May-29-2019, 02:48 AM
Last Post: heiner55
  [split] Array in numpy aapurdel 1 558 May-25-2019, 08:05 PM
Last Post: buran
  [numpy]add a value to an array elmismo999 1 701 May-23-2019, 04:15 PM
Last Post: michalmonday

Forum Jump:


Users browsing this thread: 1 Guest(s)