numpy issue with anaconda and pycharm - numpy

I have installed pycharm , anaconda and python and trying to import numpy.I have changed the interpeter(system interpeter path to anaconda3/python.exe) path and have succesfully installed numpy (at least according to pycharm) and use the "import numpy as np" code to import it but for some reason numpy doesnt seem to work. When I try to create a 2d array , I get an error about how a list must be indices or slices and not tuple.I am pretty sure this means that numpy isn't actually imported. I would appreciate if you guys tell me what I am doing wrong because this is really frustrating me.
Thanks in advance for your answers.

Related

I'm having a minor problem running Tensorflow with Colab

I am a beginner who just learned about TensorFlow using Google Colab.
As in the attached image file, numbers 10 to 13 are underlined in tensorflow.keras~, what is the problem?
It's probably a function that indicates a typo, but there's nothing wrong with running it.
enter image description here
This underline error was an ongoing issue earlier in Google Colab, which is resolved now. Please try again replicating the same code in Google colab what you mentioned in the screen shot and let us know if the issue still persists at your end.
Please check the code below: (I replicated the same in Google Colab with python 3.8.10 and TensorFlow 2.9.2)
from keras.preprocessing import Sequence will show the error as you are not giving proper alias to import the Sequence API which is provided correctly in next line (using tensorflow.keras.preprocessing prefix or tensorflow.keras.utils).

How can I draw a graph using networkx without explicitly calling matplotlib?

I am making interactive worksheets in Jupyter Notebook, introducing people to NetworkX. Suddenly, the nx.draw() command is not creating an output of a graph. It was working fine before, and I haven't changed anything about the code I was using. For example, one block of code that was working fine before was:
import networkx as nx
G2 = nx.Graph()
G2.add_nodes_from([1,2,3,4,5,6,7])
edgelist = [(1,4),(1,6),(1,7),(2,5),(2,6),(3,7),(4,6),(4,7),(5,7),(6,7)]
G2.add_edges_from(edgelist)
nx.draw_networkx(G2, with_labels=True, node_color = 'y')
Now, no errors come up, but neither does a graph. I have looked and seen that other people fixed this issue bu using plt.show() but I don't understand why I suddenly need to include that when I didn't have to before. Does anyone know a way I can avoid importing matplotlib and using the plt.show() command?
Perhaps the issue is to do with some other package I have or something to do with jupyter notebook?
EDIT: It has been pointed out to me that matplotlib is a package dependency so technically there is no way of drawing a graph in networkx without using matplotlib. I understand that, but is there a way to do it without explicitly calling matplotlib?

VS Code and tensorflow

I just imported the tensorflow module, can anyone tell me why this message keeps coming up on my console every time I run my program and how I can get rid of it?
EDIT: I found that using
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
before
import tensorflow
helped clear my console.

Fix no module 'layer' in current Google Colab TF version

I use Google colab (python3 GPU)
I want to run for example this repo codes but I have an error when running demo ipynb in these lines:
import tensorflow as tf
from layers import (_causal_linear, _output_linear, conv1d, dilated_conv1d)
When I run these two lines I have an error "no module layer"
I don't think this is a bug or something, because this repo has over 1000 stars.
I think this is rather a tf version problem.
Any ideas how to solve this?
"Layers" is a module in the package that you linked NOT in Tensorflow. See here.
BTW if you wanted to import from a submodule of tensor flow you would have to do from tensorflow.package import ....

AttributeError: module 'tensorflow.python.layers.layers' has no attribute 'Layer'

I'm learning an article called "Attention is all you need", and I'm Trying to learn the code (of the official article from github), and I'm getting weird error, the error is:
"AttributeError: module 'tensorflow.python.layers.layers' has no attribute 'Layer'"
The code generating the error:
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import tensorflow as tf
class Attention(tf.layers.Layer)://this is the line the generating the error
Now this is weird because when checking online, all the solutions were version problem of tensorflow, and I have a sufficient version (by the answers online) 1.7.0, Also my python version is 3.6.4.
One more thing is it normal that in the error description it's written:"tensorflow.python.layers.layers" and not just "tensorflow.layers"?
Thanks a lot for your help.
So I faced the same error but discovered that my version of tensorflow (which
is 2.0) moved layers from the tf package (tf.layers) to tf.keras.
An easy fix would be to replace tf.layers with tf.keras.layers
From: https://www.tensorflow.org/api_docs/python/tf/layers/Layer
tf.layers.Layer is considered legacy, and we recommend the use
of tf.keras.layers.Layer instead
After this you may get another error regarding Keras since tensorflow needs to be version > 1.4 so update tf like so:
pip install --upgrade tensorflow