As a parent or caregiver, you’ve likely encountered the challenge of a frustrated child. This is an experience as universal as it is daunting. Children, much like the rest of us, are not born with an innate ability to manage frustration effectively. However, recognizing and addressing these feelings in children is not just about soothing the present moment; it’s about building resilience. With the further complications brought about by the pandemic, the task of guiding children through their frustrations has become even more critical. In this article, we will delve deep into the roots and management of frustration in children, empowering you to help the young ones navigate their emotions and foster lasting resilience.
Low Frustration Tolerance (LFT) is a term that describes the difficulty some children face in handling challenging situations without becoming overwhelmed by negative emotions. If your child becomes irritable, has emotional outbursts, or throws temper tantrums more frequently than seems typical, they may be experiencing LFT. Recognizing the hallmarks of LFT is the first step in helping your child overcome these hurdles.
It’s important to differentiate between high and low frustration tolerance. Children with high frustration tolerance can weather difficulties with calm and perseverance, whereas those with low tolerance may quickly resort to anger or despair. Understanding where your child falls on this spectrum can significantly affect how you approach their frustration.
The difference between high and low frustration tolerance goes beyond the immediate reactions to stressors. It can have far-reaching implications for your child’s development, influencing everything from their social interactions to their approach to problem-solving. In the following sections, we explore these aspects more closely.
At the heart of LFT are complex brain networks and temperamental factors. Genetics and innate temperament can predispose a child to lower frustration tolerance, but so can the environment they’re growing up in. It’s crucial to comprehend the role these factors play as you navigate your child’s frustrating moments.
The influence of parenting cannot be overstated. An overly strict or permissive approach can hinder a child’s ability to self-regulate, increasing the chances of LFT. Conversely, a balanced approach can promote a healthier response to frustrations.
Knowing the signs of high frustration, such as distress at criticism, aggressive physical behaviors, or the development of irrational beliefs, is essential for early intervention. Recognizing these signs can provide you with the opportunity to step in and offer support before emotions escalate.
If LFT is not addressed, it can lead to more severe behavioral issues like oppositional defiant disorder. Such conditions can have a negative impact on all aspects of a child’s life, from academic performance to social interactions.
Besides behavioral issues, untreated LFT can lead to problems at school and with peers. Difficulty dealing with frustration can make it hard for children to concentrate on tasks or work collaboratively with others, hindering their learning and social development.
Long-term high frustration levels can also translate into mental health risks. It is important for parents and caregivers to understand these potential consequences in order to take proactive steps in addressing LFT.
Your empathetic response sets the tone for how a child manages frustration. Showing understanding and mirroring emotional regulation can teach them how to handle their feelings.
It’s not just about responding to the frustration, but doing so in sync with your child’s emotional state. This process, known as co-regulation, involves you participating in your child’s emotional experiences and helping them navigate through them. By doing so, you provide a safe space for them to learn and understand their emotions.
To foster a sense of control and capability in your child, encourage them to engage in problem-solving and to think proactively. This not only offers them strategies to deal with frustration at that moment but also helps them develop skills that will benefit them throughout their lives.
A warm, consistent, and responsive parenting style is key. This kind of environment supports a child’s learning to cope with frustration positively and constructively, bolstering their resilience and ability to tackle challenges head-on.
Often, frustration can be exacerbated by unmet physical needs. Ensuring that your child is well-rested, fed, and physically healthy can significantly decrease their levels of frustration.
Teaching your child how to identify and articulate their emotions is a fundamental aspect of emotional coaching. Additionally, providing them with a suite of coping skills will enable them to deal with frustration in a healthy manner. This also highlights the importance of parenting training to better equip caregivers to handle such emotional challenges.
For children with developmental disorders such as ADHD or Autism, the strategies may need to be tailored to fit their specific challenges and needs. In such cases, professional support might be necessary to provide additional guidance.
Activities recommended by experts include breathing exercises, creating calming spaces within the home, engaging in physical activities, and using music or art as outlets for expression. These not only serve as ways to cope, but also as avenues for children to explore and express their emotions.
For some children, sensory-focused techniques such as playing with stress balls or kinetic sand might provide the necessary comfort and distraction to deal with moments of intense frustration.
Remember that each child is different, and what works for one may not work for another. It’s important to tailor these activities to your child’s preferences and needs. Check out more activities here.
Every child reacts differently to frustration, and understanding your child’s specific temperament is crucial. Your responses should be customized to their unique needs and personality.
Together with your child, work on identifying specific triggers of frustration and establish constructive responses to those situations.
Before addressing the behavior that results from frustration, it’s important to connect with your child. This means understanding their feelings and offering comfort, serving as a foundation for teaching them how to manage their emotions effectively.
Acknowledging when you need help is important. If your child’s frustration is significant and persistent, seeking additional support from child development specialists can be beneficial.
Learning to manage frustration is not a luxury; it’s an essential life skill. Through your guidance and support, your child can learn to navigate their emotions and develop the resilience necessary for a healthy and successful life.
We have touched upon various strategies and insights that are crucial for helping children cope with frustration. By adopting an empathetic and proactive approach, you can guide your child towards emotional maturity and resilience. Do you have strategies that work for your child, or are you seeking advice? Feel free to share your experiences and questions in the comments below.
The post Understanding Frustration in Children appeared first on Marina Mele's site.
ChatGPT is a new artificial intelligence chatbot that has taken the world by storm. Developed by OpenAI and launched in November 2022, ChatGPT can engage in conversational dialogues and perform a variety of tasks like answering questions, explaining concepts, summarizing text passages, and even generating new content like articles, poems and computer code.
But what exactly is ChatGPT and how does this impressive new AI work? Let’s break it down.
All the images of this post have been generated using Midjourney.
ChatGPT is based on a large language AI model called GPT-3, which was created by OpenAI in 2020. GPT-3 uses a specialized deep learning technique called transformers to analyze massive amounts of text data and understand the patterns and structure of human language. Check this article if you want to know more about large language models.
Building on the capabilities of GPT-3, OpenAI trained ChatGPT specifically to have natural conversations and respond to a wide range of prompts and instructions. After over a year of development and training on vast datasets, ChatGPT was unveiled to the public in a beta version in November 2022, immediately capturing people’s attention and imagination.
Other tech companies like Anthropic and Google have also launched their own AI chatbots, such as Claude and Bard, to rival ChatGPT. Each model possesses its unique strengths, and a detailed comparison will be provided later in the article.
When you give ChatGPT a written prompt or question, it analyzes the text to understand the intent and context. It then generates a response by predicting the most likely next words in a sequence, based on the patterns it learned during its training.
ChatGPT progressively generates its response word-by-word, while continuously referring back to the original prompt for context. This allows it to have coherent, multi-turn conversations that stay on topic.
The key to ChatGPT’s conversational abilities lies in its training methodology. During training, ChatGPT was shown many real examples of human conversations, questions and answers from diverse sources on the internet. It uses these examples to learn the nuances of natural dialogue.
ChatGPT was also trained using a technique called reinforcement learning from human feedback. Essentially, it was rewarded when it generated responses that humans rated as satisfactory, and penalized for inadequate responses. This allowed it to keep improving the quality and relevance of its replies.
ChatGPT offers a wide range of useful applications and capabilities that showcase the technology’s current strengths and potential. However, as with any AI system, it also comes with significant limitations that warrant consideration.
First, we will explore some of the key ways ChatGPT can provide value and assistance. While not an exhaustive list, these applications demonstrate ChatGPT’s diverse conversational skills.
These examples offer just a sample of ChatGPT’s expanding capabilities. Its conversational nature enables a wide variety of functions through natural prompts and instructions. However, ChatGPT is far from flawless. Next we will discuss key current limitations to understand its deficiencies alongside its utilities.
The breadth of tasks ChatGPT can perform is impressive. It can hold conversations, explain concepts, summarize texts and generate new content in various styles. However, as an AI system still in development, ChatGPT has significant limitations to keep in mind.
Therefore, while remarkably capable, ChatGPT cannot fully replace human intellect just yet. Relying solely on it for critical advice would be unwise. That said, various plugins and integrations are expanding ChatGPT’s capabilities beyond just text generation. And for less high-stakes applications like drafting emails or summarizing concepts, ChatGPT proves very useful.
While often accurate, ChatGPT cannot be relied upon for 100% factual correctness. Any high-stakes use should involve human verification of its outputs.
While these limitations highlight areas for improvement, they do not negate ChatGPT’s impressive capabilities. Understanding its boundaries allows for responsible, informed use – avoiding overreliance or unrealistic expectations. ChatGPT was built to generate likely text continuations, not possess encyclopedic knowledge. By recognizing its strengths as a conversational model and anticipating its weaknesses, we can have productive interactions without frustration.
Moving forward, it will be insightful to explore how alternative AI systems attempt to address ChatGPT’s limitations. In the next section, we will compare ChatGPT to its two major competitors – Claude and Bard – to see how they stack up in terms of capabilities, limitations, and overall utility. Examining the contrasts and similarities with these other natural language models will provide useful perspective on the current state and trajectory of this rapidly evolving technology.
ChatGPT made a big splash as the first widely available conversational AI, but it now faces competition from Claude created by Anthropic, and Bard from Google. How do these alternative natural language models compare?
Claude is an AI assistant developed by startup Anthropic to prioritize safety and integrity. Like ChatGPT, it uses a transformer neural network architecture for natural language processing. However, Anthropic employed a technique called Constitutional AI to align Claude’s goals and values with human preferences.
As a result, Claude is said to exhibit less harmful bias and is more cautious about generating dangerous or unethical content compared to ChatGPT. It also incorporates self-supervised learning to better handle novel situations outside its training data.
It has a bigger context than ChatGPT or Bard, of about 100k tokens. This gives it the ability to read longer articles, even short books, and retain the information within a chat for much longer.
On the other hand, Claude’s capabilities lag behind ChatGPT and Bard when it comes to conversational breadth and creativity. Its responses tend to be simpler and more constrained. Though possibly safer, Claude lacks some of the expressiveness that makes ChatGPT engaging.
Google’s Bard aims to rival ChatGPT as an AI assistant that can explain concepts, generate content, and converse naturally. It is based on Google’s LaMDA model rather than GPT, featuring deep neural networks and trillions of parameters.
In initial tests, Bard appears significantly more grounded in facts compared to ChatGPT, with Google’s extensive Knowledge Graph likely providing useful context. However, Bard’s responses are often shorter and it struggles with more complex conversational prompts.
However, Bard also has access to the internet. This means that it can keep its knowledge up-to-date by reading the latest news articles, blog posts, and social media posts. This gives Bard a significant advantage over ChatGPT, which in general, it’s not able to access the internet (only paid users and with the browsing on).
For example, if you ask Bard about the latest news, it will be able to tell you about the most recent events. It will also be able to provide you with links to articles and other sources of information so that you can learn more.
In general, I use
But my recommendation is that you should try the different tools and discover which one works better for your specific needs. I sometimes ask the same question to two different chats, to compare, and even discover new functionalities. You can have a browser window specifically for your AI tools like Bard, ChatGPT or Claude.
And you, which of them do you use in your daily live? Leave a comment with your specific use cases. I’d like to know!
Follow me to stay tuned to the latest news regarding AI. You can subscribe to my blog here, or to my weekly AI newsletter at marinamele.substack.com.
The post What is ChatGPT and how it compares to Bard and Claude appeared first on Marina Mele's site.
Do you ever wish you could just describe an image in your mind and have it magically appear on your screen? Well, thanks to recent advances in artificial intelligence, we’re getting closer than ever to making that sci-fi dream a reality. In this post, we’ll explore the history of how AI has evolved to generate increasingly stunning and creative images from text descriptions alone.
It all started with an exciting breakthrough in 2014 from researcher Ian Goodfellow and his colleagues. They introduced an AI technique called generative adversarial networks, or GANs for short. GANs pit two neural networks against each other in a competitive game of counterfeiting. One AI generates fake images while the other tries to detect the fakes. Through this adversarial training process, the “generator” keeps getting better at producing realistic images that can fool its partner AI. GANs were like a creative spark that ignited the field of neural art generation.
Suddenly, GANs were creating photorealistic pictures of everything from human faces to stunning landscapes. Researchers also adapted GANs for applications like transferring artistic styles from one image to another. However, GANs had their limitations. They were tricky to train properly and often got stuck churning out a limited variety of similar-looking images.
The AI community turned to a different technique to overcome these challenges – Transformers. Originally created for processing language in applications like chatbots, Transformers proved to be a key ingredient in the next generation of text-to-image models. In 2018, OpenAI introduced GPT-2 which used the Transformer architecture to generate remarkably human-like text.
Researchers soon realized they could train Transformers like GPT-2 on massive datasets of image and caption pairs. The result was DALL-E in 2021, which could generate diverse and realistic images from text prompts. DALL-E’s outputs were still a bit rough around the edges though.
This brings us to CLIP, another pivotal model in text-to-image generation by OpenAI. CLIP provided the missing link between understanding text and images. By training on captioned images, CLIP learned to embed text and images into a common mathematical space. This enabled better alignment between text descriptions and the generated image results.
CLIP acted as a guiding hand for image generation AIs like DALL-E, dramatically improving the quality and accuracy of the images produced from text prompts. But CLIP was still hungry for more data and processing power to reach its full potential.
That’s where diffusion models came to the rescue! Diffusion models simulate the natural process of particles diffusing and coalescing to gradually transform random noise into coherent images. Researchers discovered that running the diffusion process in a compressed latent space made image generation much more efficient.
Latent Diffusion combined with guidance from CLIP resulted in huge leaps in quality and creativity. Now high-resolution images poured out of the models with incredible detail and precision tailored to the text prompts. Services like DALL-E 2 from OpenAI brought these advanced text-to-image models directly into the hands of everyday users through intuitive apps and websites.
Of course, the story doesn’t end here. Generative AI is advancing rapidly with new techniques like Stable Diffusion making high-quality image generation widely accessible and customizable. There are still challenges around consistency, coherence and photorealism, but the future looks bright as research continues.
The journey so far has been remarkable. In less than a decade, AI has evolved from simply classifying images to creatively synthesizing them. Who knows what new innovations and applications the next decade may bring as generative models continue to mature. But one thing’s for sure – the worlds of art, media and communication will never be the same!
Which part of this incredible AI image journey excites you the most? Let me know in the comments! I’d love to hear your thoughts.
The post The Incredible Journey of AI Image Generation appeared first on Marina Mele's site.
Artificial Intelligence (AI) is increasingly becoming a part of our lives. From facial recognition systems to self-driving cars, AI technologies are changing the way we live and work. But with this increasing presence of AI in our lives comes a need to ensure that it is used in a safe, ethical, and responsible way.
In response to this need, the European Union has proposed the Artificial Intelligence Act (AI Act). This proposed regulation seeks to ensure that AI is developed and used in a way that protects the fundamental rights and freedoms of individuals and society. It sets out a number of requirements for AI systems, such as requiring human oversight, fairness, non-discrimination, privacy, data protection, safety, and robustness.
This blog post will look at the AI Act in more detail, exploring its purpose, its categories, and its main concerns. We will also look at how the Act is designed to protect individuals fundamental rights and how it can be implemented in a way that ensures AI is used for good.
The Artificial Intelligence Act (AI Act) is a proposed regulation of the European Union that aims to introduce a common regulatory and legal framework for artificial intelligence. It was proposed by the European Commission on 21 April 2021 and is currently being negotiated by the European Parliament and the Council of the European Union.
The purpose of the AI Act is to ensure that AI is developed and used in a way that is safe, ethical, and responsible. The Act sets out a number of requirements for AI systems, including requirements for human oversight, fairness, non-discrimination, privacy, data protection, safety, and robustness.
The AI Act is a complex piece of legislation, but it has the potential to ensure that AI is used in a way that benefits society. The Act is still under negotiation, but it is expected to come into force in 2026.
The AI Act defines three categories of AI systems:
Let’s see each of these categories in more detail.
The AI Act defines unacceptable risk systems as those that pose a serious threat to the fundamental rights and freedoms of natural persons, such as their right to privacy, non-discrimination, or physical integrity.
Some examples of unacceptable risk systems include:
The AI Act prohibits the development and use of unacceptable risk systems. This means that companies and organizations cannot develop or use these systems in the European Union.
There are a few exceptions to the prohibition on unacceptable risk systems. For example, the prohibition does not apply to systems that are used by law enforcement agencies for the prevention or detection of crime. However, even in these cases, the systems must be used in a way that complies with the law and that does not violate individuals’ fundamental rights.
The prohibition on unacceptable risk systems is an important part of the AI Act. It is designed to protect individuals’ fundamental rights and to ensure that AI is used in a way that is safe and ethical.
The AI Act defines high-risk systems as those that pose a significant threat to the safety or fundamental rights of natural persons, such as their right to life, health, or property.
Some examples of high-risk systems include:
The AI Act sets out specific requirements for high-risk AI systems. These requirements include:
The AI Act also requires providers of high-risk AI systems to register their systems with a central EU database. This will allow the authorities to monitor the use of these systems and to take action if they are used in a way that violates the law.
The requirements for high-risk AI systems are designed to ensure that these systems are used in a safe and ethical way. They will help to protect individuals’ fundamental rights and to ensure that AI is used for good.
The AI Act defines minimal risk systems as those that do not pose any significant threat to the safety or fundamental rights of natural persons. This means that they are considered to be relatively safe and ethical.
Some examples of minimal risk systems include:
The AI Act does not impose any specific requirements on minimal risk systems. However, they must still comply with general EU law, such as the General Data Protection Regulation (GDPR).
The AI Act also requires providers of minimal risk systems to make certain information publicly available, such as the purpose of the system and the data that it uses. This will allow users to make informed decisions about whether or not to use these systems.
The minimal risk category is designed to ensure that AI systems that are considered to be relatively safe and ethical are not overregulated. This will help to promote the development and use of these systems, which can benefit society in a number of ways.
The AI Act is a complex piece of legislation that has been met with mixed reactions from the AI community. Some people have praised the Act for its ambitious approach to regulating AI, while others have criticized it for being too complex and burdensome.
Here are some of the main concerns that have been raised about the AI Act:
These are just some of the main concerns that have been raised about the AI Act. It is important to note that the Act is still under negotiation, so it is possible that some of these concerns will be addressed before it comes into force. However, the Act is a complex piece of legislation, and it is likely that there will be further debate about it in the coming months and years.
The AI Act is a proposed regulation from the European Union that aims to ensure that AI is developed and used in a safe, ethical, and responsible way. It sets out a number of requirements for AI systems, such as requiring human oversight, fairness, non-discrimination, privacy, data protection, safety, and robustness. The Act is still under negotiation, but it is expected to come into force in 2026.
The AI Act is an ambitious attempt to regulate AI in the European Union. It sets out a number of requirements that are designed to ensure that AI is used in a way that benefits society. However, the Act has also been met with mixed reactions, and there are still a number of concerns that need to be addressed before it comes into force.
For example, some people have expressed concern that the definition of AI is too broad, and that the requirements for high-risk AI systems are too burdensome. Others have argued that the penalties for non-compliance are too weak.
Ultimately, the AI Act is a complex piece of legislation that will have a significant impact on the development and use of AI in the European Union. It is important that these concerns are addressed, and that the Act is implemented in a way that ensures that AI is used in a safe, ethical, and responsible way.
The post AI and Fundamental Rights: How the AI Act Aims to Protect Individuals appeared first on Marina Mele's site.
In this blog post, we will explore the concept of critical thinking and its role in fostering creativity and problem-solving. We will look at how critical thinking can help to identify biases and challenge conventions, explore alternative ideas and solutions, and broaden perspectives. We will also discuss the importance of developing critical thinking skills, such as reading, researching, questioning, and practicing mindfulness. Finally, we will focus on how critical thinking can empower individuals to make informed decisions and become more confident and independent in their thinking. So let’s get started!
“It is the mark of an educated mind to be able to entertain a thought without accepting it.”—Aristotle
Critical thinking is the process of actively and skilfully conceiving, applying, analysing, synthesizing and evaluating information gathered from observation, experience, reflection, reasoning, or communication. It involves a careful examination of the facts, and often involves the questioning of underlying assumptions. It is a cognitive process that requires the development of skills, such as analysis and evaluation, in order to make sound judgments about the validity of evidence and the overall worth of an argument.
There are many different types of critical thinking skills, and each of them requires the ability to identify and evaluate the credibility of evidence, and to draw conclusions from that evidence.
The benefits of developing critical thinking skills include the ability to think objectively and make sound judgments, the ability to identify and evaluate evidence, the ability to draw conclusions from evidence, and the ability to make decisions quickly and confidently. Critical thinking can also help to improve problem-solving and communication skills, as well as increase one’s capacity for creativity and innovation.
Examples of critical thinking can be seen in everyday life. For instance, when a parent is presented with a difficult decision regarding their child, they may use critical thinking skills to evaluate the different options and come to an informed conclusion. Additionally, when a student is presented with a complex problem in mathematics, they may use critical thinking skills to break down the problem into its components and develop an effective strategy to solve it. In business, critical thinking can be used to evaluate new ideas and strategies, and to make decisions about how best to allocate resources.
Creativity and critical thinking are closely intertwined. When people are encouraged to be creative, they are also encouraged to think outside the box and explore alternative ideas and solutions. Through critical thinking, people can consider different perspectives and explore different possibilities and thus, help them with creativity and innovation.
Critical thinking can also help to identify biases and challenge conventions. For example, here are some common biases:
By questioning the assumptions underlying an argument or situation, people can develop a more complete understanding of the issue at hand. This can help to bring new insight and uncover potential solutions that may not have been considered before.
Moreover, critical thinking can also help to open people up to new perspectives and broaden their views. By questioning the assumptions underlying their own beliefs and ideas, people can develop empathy and understanding. They can also learn to consider different viewpoints and develop an appreciation of diversity. This can help to foster creative problem-solving and spark new ideas.
Here are some tips to develop critical thinking skills:
In conclusion, critical thinking is an important skill for developing creativity and problem-solving. It involves the ability to identify and evaluate evidence, draw conclusions from evidence, and make decisions quickly and confidently. Developing critical thinking skills requires the ability to read, research, question, and practice mindfulness. When people are encouraged to think critically, they can learn to challenge assumptions, explore alternative ideas and solutions, and broaden their perspectives. This can help to foster creativity and empower individuals to make informed decisions.
The post Thinking Outside the Box: Creative Problem-Solving with Critical Thinking appeared first on Marina Mele's site.
Raising children is no easy task. It requires patience, consistency, and a lot of guidance. As parents, we have the responsibility to teach our children the important skills they will need to live successful and rewarding lives. One such skill is assertiveness.
Assertiveness is a form of communication which involves expressing oneself openly and honestly, with consideration for the rights of others. It is an important skill for children to develop as it helps them become more confident and secure in their self-expression. It encourages children to have healthy relationships with others, respect boundaries and stand up for themselves.
In this blog post, we will explore why assertiveness is important for children, the main benefits of being assertive, and tips on how to teach assertiveness.
Assertiveness entails expressing one’s opinions or perspectives confidently and respectfully. And I consider it a crucial skill for children as it allows them to communicate their thoughts, emotions, and ideas clearly while also considering the feelings of others.
But let me emphasize that assertiveness is not the same as aggression. It is important to differentiate between making your point in a confident and respectful way, versus using forceful and intimidating language that can be off-putting to others. Additionally, assertiveness should be expressed in a way that is honest and direct, but not rude or condescending.
Assertiveness can be useful to resolve problems, as it helps children to be aware of their own needs, as well as the needs of others. This awareness can then be used to come up with creative solutions to conflicts or disagreements. For example, if your child is facing a problem with a friend, they can use assertiveness to communicate what they need and come up with a plan that works for everyone.
This skill also helps children to effectively communicate with others. Through assertive communication, children are able to express their thoughts and feelings in a way that is direct but not aggressive, and allows them to be understood and taken seriously by their peers. Additionally, it can help to build trust between the involved parties, as each person is able to trust that the other is being honest and trustworthy in their interactions.
Lastly, assertiveness encourages children to take an active role in advocating for their needs and wants. It helps them to recognize their own value and to recognize that their voice is important. This can be especially beneficial for shy or introverted children, as it gives them confidence to speak up and make their opinions known.
The first tip I want to share is to model assertive behaviour. This means that I express my own feelings in a respectful and direct manner, without being aggressive or passive. I also ensure that I listen to my children and allow their opinions, feelings and wishes to be heard. By doing this, I hope to teach my children that they can express themselves in a confident, non-aggressive manner too.
Another tip is to practice role-play. This can be done by creating scenarios in which children can practice expressing their own needs, while also respecting the needs of others. Here are some examples:
Ordering food at a restaurant: Have your child pretend to be the customer and you play the role of the server. Encourage your child to practice ordering politely and assertively, making sure to speak clearly and make eye contact.
Standing up to a bully: Create a scenario in which your child is being bullied by another child. Encourage your child to assertively communicate their feelings, telling the other child how their actions are making them feel and standing up for themselves.
Negotiating with a friend: Set up a scenario in which your child and a friend have a disagreement over something, such as sharing toys or playing a game. Encourage your child to assertively communicate their needs and wants, while also being willing to compromise and find a solution that works for both parties.
Asking for help: Create a scenario in which your child needs help with something, such as completing a task or understanding a lesson. Encourage your child to assertively ask for help, making sure to clearly communicate what they need assistance with and why.
And the last tip is that we should try to use positive assertive language when disciplining children. This means that we must explain why a certain behaviour is not acceptable and provide alternatives. Here are some examples:
I understand that you want to keep playing, but it’s time to clean up now.
I can see that you’re upset, but hitting your brother is not okay. Let’s find a better way to express your feelings.
I understand that you’re frustrated, but we don’t yell in our house. Let’s take a deep breath and try to communicate calmly.
I know you didn’t mean to spill the juice, but it’s important to clean up after ourselves. Let’s work together to clean it up.
I understand that you’re feeling angry right now, but it’s not okay to throw things. Let’s take a break and come back to this when we’re both feeling calmer.
The key is to use “I” statements, acknowledge the child’s feelings, and offer alternatives or solutions that promote positive behaviour.
As a mother and a professional, I understand the importance of setting boundaries for children. Establishing clear limits helps children learn self-control, emotional regulation, and respect for others. By using assertiveness, we can communicate our expectations and model the behavior we’d like our children to adopt. Additionally, setting boundaries helps create a sense of security for children, as they know what to expect and can navigate their environment with confidence.
Again, role-playing can be an excellent tool for teaching boundary-setting skills to children. By engaging in various scenarios, children can practice expressing their needs and standing up for themselves in a safe and controlled environment. Here are some examples:
Role-play a situation where a friend wants to borrow a favourite toy, but your child isn’t comfortable sharing it. Encourage your child to practice saying “no” assertively and calmly, explaining their reasoning without becoming defensive or aggressive.
In a role-play scenario involving peer pressure, you could have your child pretend they are at a party where friends are pressuring them to engage in activities they are uncomfortable with, such as trying a new risky game or consuming unhealthy snacks. Encourage your child to practice assertively expressing their feelings and standing their ground, while also suggesting alternative activities that align with their values.
Another role-play situation could involve addressing bullying at school. Have your child imagine they are witnessing someone being teased or mistreated. Help them practice assertively intervening by telling the bully to stop, standing up for the victim, and reporting the incident to a trusted adult. This will help them develop the confidence and skills needed to handle such situations in real life.
A scenario involving personal space boundaries could involve your child pretending to play with a friend who is consistently invading their personal space or touching them without permission. Encourage your child to practice assertively communicating their discomfort and setting clear limits on physical contact, while remaining respectful and empathetic towards their friend.
To practice assertiveness in the context of family dynamics, create a role-play scenario in which a sibling or relative is continually borrowing your child’s belongings without asking. Help your child practice expressing their feelings about the situation and setting clear boundaries around the use of their possessions, emphasizing the importance of mutual respect and communication.
Lastly, consider a role-play situation where your child needs to advocate for themselves in an academic setting. For example, they could pretend they’ve been given an unfair grade on a project. Encourage your child to practice assertively discussing their concerns with the “teacher” (played by you or another family member), presenting evidence to support their case and respectfully asking for a grade reconsideration. This will help them develop the skills needed to navigate challenging situations in their educational journey.
In conclusion, assertiveness is an important skill for children to develop. It helps to foster healthy relationships, encourages honest communication, and allows children to stand up for themselves in challenging situations. By modeling assertive behavior and engaging in role-play scenarios, we can teach children how to express themselves confidently and respectfully. This, in turn, will help them lead more meaningful and fulfilling lives.
The post Assertiveness: A Crucial Skill for Children’s Personal Growth appeared first on Marina Mele's site.
A vegades, quan parlem amb els nens, utilitzem frases que poden pensar als nens que son responsables de les emocions dels adults. En aquest article t’explico quines frases son, i quins problemes hi ha en utilitzar-les.
Has dit 3 vegades a la teva filla que reculli la joguina amb la que estava jugant i que ha deixat tirada al menjador, i cap de les vegades t’ha contestat ni t’ha fet cas. A la quarta vegada, dius alguna cosa com: t’he dit varies vegades que recullis la joguina, m’estas enfadant!
Han vingut convidats a sopar i el teu fill no ha volgut seure al costat d’un d’ells, i aquest ha dit: No vols seure al meu costat? ai, que trist que em poses.
Estàs intentant fer una cosa i els nens estan corrent amunt i avall cridant, i no et fan cas quan els dius que estiguin tranquils, i al final dius: voleu parar, m’esteu posant nerviós!
O algun dia que esteu jugant molt bé amb els nens i dius: estic feliç quan tu estàs feliç.
Quin problema hi ha amb aquestes frases? Doncs que si t’hi fixes, aquestes frases creen una relació directa entre les accions dels nens i les emocions dels pares o els adults. El nen és el responsable, al no recollir, que el seus pares s’enfadin. El nen és responsable de posar trist a un convidat perquè no vol seure al seu costat. El nen és resonsable de posar nerviós al seu pare. El nen és responsable de que la seva mare sigui feliç.
Frases com aquestes, acaben responsabilitzant als nens de les emocions dels adults. Quin pes més gran per un nen, no creus?
Quan els meus fills no em contesten, em sento frustrada. Inclús a vegades m’enfado perquè els repeteixo varies vegades una cosa, em miren, i segueixen jugant com si res.
Però és important adonar-se’n que per una banda, el nen en aquell moment s’ho està passant molt bé, està distret, està absorvit en el joc o en la situació, i el seu cap no està pensant ara ignoraré el que em diuen els pares i no contestaré. M’ha passat varies vegades d’alçar la veu per cridar-los l’atenció i que reaccionessin com ai, que passa? ens havies dit alguna cosa?.
I per l’altra, soc jo la que tinc una idea preconcebuda al cap del que hauria de passar, del que hem de fer, de com han de contestar o reaccionar. I si aquesta idea no es compleix, em genera malestar i frustració. M’explico una mica millor:
tinc al cap que els nens han de recollir les joguines al moment quan els ho demano. Si no em fan cas, em frustro, potser m’arribo a enfadar.
fem tard a l’escola i els nens van tranquil·lament per la casa buscant una joguina per emportar-se pel camí. M’estresso perquè vull arribar puntual i veig que si seguim així, no ho farem.
En totes aquestes situacions, soc jo la responsable del que sento i com actuo, no els altres. I quan me n’adono i ho accepto, passo a pensar de forma constructiva:
Quan no m’escolten, m’acosto a ells, els toco el braç per cirdar-los l’atenció, els demano que em mirin un moment, i quan tinc tota la seva atenció i m’asseguro que m’estan escoltant, llavors els puc dir algo així com: veig que us ho esteu passant molt bé jugant, però ara és l’hora d’anar a sopar i hem de recollir tot el que heu deixat al menjador. Després de sopar, o demà podreu seguir jugant.
Quan fem tard a l’escola, he d’acceptar que sí, que arribarem tard, però puc buscar algun joc per anar caminant ràpid a l’escola. I el pròxim dia, aixecar-nos 5 minuts abans potser, o no despistar-me quan estem tots esmorzant, per començar la rutina de sortir per la porta una mica abans.
Tot això per què ho explico? Doncs perquè és important que siguem conscients que som nosaltres els únics responsables de les nostres emocions i de com actuem. D’aquesta manera no responsabilitzarem als nostres fills, i també els podrem transmetre que ells son els responsables de les seves emocions.
Frases com m’estàs enfadant fan que el nen es senti responsble de la felicitat o les emocions que senten els adults, i això pot posar molta pressió al nen.
Si veuen al seu pare trist o enfadat, poden pensar, he estat jo qui ho ha fet. Dec haver dit alguna cosa que l’ha posat trist. Però ves a saber si el seu pare està així per alguna cosa que no té res a veure amb el que acaba de passar, o com sovint passa, és un conjunt de coses. Però els nens poden acabar tenint un sentiment de culpa, i de responsabilitat davant d’aquestes emocions dels adults.
Això també pot provocar que els nens siguin més sensibles a ser manipulats o a cedir a xantatges emocionals: per exemple, fer alguna cosa que li han demanat perquè estiguin contentes les persones que li demanen, ja siguin adults, companys d’escola, cosins, etc.
Però no només això, també si ells estan tristos o enfadats, també deleguen la responsabilitat de provocar aquestes emocions a algú altre. Creuen que les seves emocions les ha provocat algú altre, i per tant, esperen que des de fora, les arreglin.
El fet de transmetre als nostres fills que ells son els responsables de les seves emocions i de com actuen, fa que tinguin el control sobre elles, i que les pugin apendre a gestionar. Hem d’ensenyar-los que totes les emocions son naturals, i que a vegades no tenen el control del que senten, però sí de com actuen.
Una de les coses que em va bé quan llegeixo sobre qualsevol tema son exemples de com aplicar el que acabo de llegir. M’ajuden a pensar en quines situacions ho puc fer diferent, puc millorar, i també al revés: faciliten que quan em trobi en aquestes situacions, me’n recordi del que he llegit, i de com puc actuar.
Aquí van alguns exemples:
Podem expressar els nostres sentiments, però fer-ho des del punt de vista de la nostra responsabilitat, no responsabilitzar als altres.
Estic trista perquè he tingut un mal dia a la feina, però sé que ja passarà
Estic trista perquè no he aconseguit el que volia, però he d’acceptar la situació i buscar altres opcions
Estic experimentant molta frustració en aquest moment, però això no té res a veure amb tu. És només una cosa que està passant en mi i ho estic gestionant.
Ensenyar als nostres fills que les emocions no son bones ni dolentes, son naturals.
És normal sentir-se trist/a o enfadat/a a vegades. És una part normal de la vida i podem aprendre a gestionar aquestes emocions.
Sentir tristesa o ràbia no és dolent, només ens està indicant que alguna cosa ens afecta.
No has de preocupar-te per sentir-te nerviós o poruc, és normal i tots ho sentim de vegades.
Ensenyar als nostres fills que a vegades no podem controlar les emocions, però sí que som responsables de les nostres accions.
Entenc que estiguis enfadat, però pegar a la teva germana no està bé.
A vegades les emocions poden ser molt intenses i difícils de controlar, però sempre podem decidir com reaccionar a aquestes emocions.
És normal sentir-se frustrat o trist, però és important que no ens deixem portar per aquestes emocions i pensem abans de reaccionar.
Si tens alguna frase útil, que et serveixi per ajudar als nens a responsabilitzar-se de les seves emocions, i que aprenguin a gestionar-les, si us plau, afegeix-ho als comentaris per poder-ho incloure també aquí. Gràcies!
En resum, és important que els nens entenguin que no són responsables de la felicitat dels pares. La felicitat és una responsabilitat individual, i no hem de descarregar-la en altres persones, especialment en els nostres fills. És important que els nens aprenguin a assumir la seva pròpia felicitat i que se’ls permeti prendre decisions i expressar les seves emocions. Això no només els farà més feliços, sinó que també els ajudarà a desenvolupar habilitats socials i emocionals que els seran molt útils en el futur.
The post Els nens no son responsables de les emocions dels altres appeared first on Marina Mele's site.
Sometimes, when we talk to our kids, we use phrases that can make them feel responsible for the emotions of adults. In this article, I explain which phrases and what problems there are in using them.
You’ve told your daughter three times to pick up the toy she was playing with and left on the dining room floor, and each time, she didn’t answer or even listen. On the fourth time, you say something like, I’ve told you several times to pick up the toy, you’re making me angry!
Guests have come over for dinner, and your child doesn’t want to sit next to one of them, and the guest says, You don’t want to sit next to me? Oh, you’re making me sad.
You’re trying to do something, and the kids are running around and shouting, and they’re not listening when you tell them to calm down, and eventually you say, Can you stop? You’re making me nervous!
Or some day when you’re playing really well with the kids, you might say, I’m happy when you’re happy.
What’s the problem with these phrases? Well, if you pay attention, these phrases create a direct relationship between the actions of the children and the emotions of the parents or adults. The child is responsible for making their parents angry because they didn’t pick up their toys,. The child is responsible for making a guest sad because they didn’t want to sit next to them. The child is responsible for making their father nervous or the child is responsible for making their mother happy.
Phrases like these end up making children responsible for the emotions of adults. What a heavy burden for a child, don’t you think?
When my children don’t answer me, I feel frustrated. Sometimes I even get angry because I repeat something to them several times, they look at me, and continue playing as if nothing happened.
But it’s important to realize that on the one hand, the child is having a great time, is distracted, absorbed in the game or situation, and their mind is not thinking, I’m going to ignore what my parents say and not answer. It’s happened to me several times when I raise my voice to get their attention and they react with, What happened? Did you say anything?
And on the other hand, it’s me who has a preconceived idea in my mind of what should happen, what we should do, how they should answer or react. And if that idea is not fulfilled, it generates discomfort and frustration for me. Let me explain it a litter bit better:
For example, in my head I think children should pick up their toys when I ask them to. If they don’t listen, I get frustrated and maybe even angry.
We’re running late for school and the children are calmly looking for a toy to take with them on the way. I get stressed because I want to arrive on time and I see that if we continue like this, we won’t make it.
In all these situations, I am responsible for what I feel and how I act, not others. And when I realize and accept it, I start thinking constructively:
When they don’t listen to me, I approach them, touch their arm to get their attention, ask them to look at me for a moment, and when I have their full attention and make sure they are listening, then I can say something like: I see that you’re having a lot of fun playing, but now it’s time for dinner and we need to pick up everything you left in the dining room. After dinner, or tomorrow you can continue playing.
When we’re running late for school, I have to accept that yes, we will be late, but I can look for some game to walk faster to school. And the next day, maybe get up 5 minutes earlier, or not get distracted when we’re all having breakfast, and start the routine of leaving a little earlier.
Why am I explaining all this? Well, because I think it’s important to be aware that we are the only ones responsible for our emotions and how we act on them. This way, we won’t blame our children, and we can also teach them that they are responsible for their emotions.
Phrases like you’re making me angry can make a child feel responsible for the happiness or emotions of adults, which can put a lot of pressure on the child.
If they see their parent sad or angry, they may think, I did something to make them feel that way. But who knows if their parent is feeling that way because of something unrelated to the child, or as often happens, it’s because many things combined. But children can end up feeling guilty and responsible for the emotions of adults.
This can also cause children to be more sensitive to manipulation or emotional blackmail: for example, doing something they’ve been asked to do to make the others happy, whether they be adults, schoolmates, cousins, etc.
But it’s not just that; if they’re sad or angry, they also delegate the responsibility for causing those emotions to someone else. They believe that someone else has caused their emotions, and therefore, they expect someone else to fix them.
Teaching our children that they are responsible for their own emotions and actions gives them control over and teaches how to manage them. We need to teach them that all emotions are natural, and that sometimes they don’t have control over what they feel, but they do have control over how they act.
One of the things that helps me when I read about any topic is examples of how to apply what I just read. They help me think about situations where I can do things differently, where I can improve. But also the opposite: they make it easier for me to remember what I’ve read when I’m in these situations and how to act.
Here are some examples:
We can express our feelings, but do so from the perspective of our responsibility, not blaming others.
I am sad because I had a bad day at work, but I know it will pass.
I am sad because I didn’t get what I wanted, but I need to accept the situation and look for other options.
I am experiencing a lot of frustration right now, but it has nothing to do with you. It’s just something that’s happening within me, and I’m managing it.
Teach our children that emotions are neither good nor bad, they are natural.
It’s normal to feel sad or angry sometimes. It’s a normal part of life, and we can learn to manage these emotions.
Feeling sadness or anger is not bad, it’s just means that something is affecting us.
Don’t worry about feeling nervous or scared, it’s normal, and we all feel it sometimes.
Teach our children that sometimes we can’t control our emotions, but we are responsible for our actions.
I understand that you are angry, but hitting your sister is not okay.
Sometimes emotions can be very intense and difficult to control, but we can always decide how to react to these emotions.
It’s normal to feel frustrated or sad, but it’s important not to let these emotions take over and think before we react.
If you have any useful phrases that can help children take responsibility for their emotions and learn to manage them, please add them to the comments so we can include them here too. Thank you!
In summary, it’s important for children to understand that they are not responsible for their parents’ happiness. Happiness is an individual responsibility, and we shouldn’t burden other people, especially our children, with it. It’s important for children to learn to take charge of their own happiness and to be allowed to make decisions and express their emotions. This not only makes them happier, but it also helps them develop social and emotional skills that will be very useful for them in the future.
The post Children are not responsible for other people’s emotions appeared first on Marina Mele's site.
Imagine what would you do if you could automate all the repetitive and boring activities you perform using internet, like checking every day the first results of Google for a given keyword, or download a bunch of files from different websites.
In this post you’ll learn to use Selenium with Python, a Web Scraping tool that simulates a user surfing the Internet. For example, you can use it to automatically look for Google queries and read the results, log in to your social accounts, simulate a user to test your web application, and anything you find in your daily live that it’s repetitive. The possibilities are infinite!
*All the code in this post has been tested with Python 2.7 and Python 3.4.
Selenium is a python package that can be installed via pip. I recommend that you install it in a virtual environment (using virtualenv and virtualenvwrapper).
Learn how to create one here, for Python 2.7 and for Python 3. It’s really useful, once you start using them you won’t stop!
Remember that to create the environment in Python 2.7, just type:
$ mkvirtualenv selenium_env
and in Python 3:
$ mkvirtualenv --python=/usr/local/bin/python3 selenium_env
where you should use your own Python 3 path.
Note: if you don’t want to use a virtual environment, you can still install the packages directly on you computer.
To install selenium, you just need to type:
$ pip install selenium
In this post we are going to initialize a Firefox driver — you can install it by visiting their website. However, if you want to work with Chrome or IE, you can find more information here.
Once you have Selenium and Firefox installed, create a python file, selenium_script.py. We are going to initialize a browser using Selenium:
import time from selenium import webdriver driver = webdriver.Firefox() time.sleep(5) driver.quit()
This just initializes a Firefox instance, waits for 5 seconds, and closes it.
Well, that was not very useful…
How about if we go to Google and search for something?
Let’s make a script that loads the main Google search page and makes a query to look for “Selenium”:
import time from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.common.exceptions import TimeoutException def init_driver(): driver = webdriver.Firefox() driver.wait = WebDriverWait(driver, 5) return driver def lookup(driver, query): driver.get("http://www.google.com") try: box = driver.wait.until(EC.presence_of_element_located( (By.NAME, "q"))) button = driver.wait.until(EC.element_to_be_clickable( (By.NAME, "btnK"))) box.send_keys(query) button.click() except TimeoutException: print("Box or Button not found in google.com") if __name__ == "__main__": driver = init_driver() lookup(driver, "Selenium") time.sleep(5) driver.quit()
In the previous code:
Finally, run your code with:
$ python selenium_script.py
Did it work? If you got an ElementNotVisibleException , keep reading!
Google search has recently changed so that initially, Google shows this page:
and when you start writing your query, the search button moves into the upper part of the screen.
Well, actually it doesn’t move. The old button becomes invisible and the new one visible (and thus the exception when you click the old one: it’s not visible to click!).
We can update the lookup function in our code so that it catches this exception:
from selenium.common.exceptions import ElementNotVisibleException def lookup(driver, query): driver.get("http://www.google.com") try: box = driver.wait.until(EC.presence_of_element_located( (By.NAME, "q"))) button = driver.wait.until(EC.element_to_be_clickable( (By.NAME, "btnK"))) box.send_keys(query) try: button.click() except ElementNotVisibleException: button = driver.wait.until(EC.visibility_of_element_located( (By.NAME, "btnG"))) button.click() except TimeoutException: print("Box or Button not found in google.com")
To sum up, I’ve created a table with the main methods used here.
Note: it’s not a python file — don’t try to run/import it
# INITIALIZE DRIVER from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait driver = webdriver.Firefox() driver.wait = WebDriverWait(driver, 5) # WAIT FOR ELEMENTS from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC element = driver.wait.until( EC.presence_of_element_located( EC.element_to_be_clickable( EC.visibility_of_element_located( (By.NAME, "name") (By.ID, "id") (By.LINK_TEXT, "link text") (By.PARTIAL_LINK_TEXT, "partial link text") (By.TAG_NAME, "tag name") (By.CLASS_NAME, "class name") (By.CSS_SELECTOR, "css selector") (By.XPATH, "xpath") ) ) # CATCH EXCEPTIONS from selenium.common.exceptions import TimeoutException ElementNotVisibleException
That’s all! Hope it was useful!
Don’t forget to share it with your friends!
The post Selenium Tutorial: Web Scraping with Selenium and Python appeared first on Marina Mele's site.
When running a complex Python program that takes quite a long time to execute, you might want to improve its execution time. But how?
First of all, you need the tools to detect the bottlenecks of your code, i.e. which parts take longer to execute. This way, you can concentrate in speeding these parts first.
And also, you should also control the memory and CPU usage, as it can point you towards new portions of code that could be improved.
Therefore, in this post I’ll comment on 7 different Python tools that give you some insight about the execution time of your functions and the Memory and CPU usage.
The simpler way to time a function is to define a decorator that measures the elapsed time in running the function, and prints the result:
import time from functools import wraps def fn_timer(function): @wraps(function) def function_timer(*args, **kwargs): t0 = time.time() result = function(*args, **kwargs) t1 = time.time() print ("Total time running %s: %s seconds" % (function.func_name, str(t1-t0)) ) return result return function_timer
Then, you have to add this decorator before the function you want to measure, like
@fn_timer def myfunction(...): ...
For example, let’s measure how long it takes to sort an array of 2000000 random numbers:
@fn_timer def random_sort(n): return sorted([random.random() for i in range(n)]) if __name__ == "__main__": random_sort(2000000)
If you run your script, you should see something like
Total time running random_sort: 1.41124916077 seconds
Anther option is to use the timeit module, which gives you an average time measure.
To run it, execute the following command in your terminal:
$ python -m timeit -n 4 -r 5 -s "import timing_functions" "timing_functions.random_sort(2000000)"
where timing_functions is the name of your script.
At the end of the output, you should see something like:
4 loops, best of 5: 2.08 sec per loop
indicating that of 4 times running the test (-n 4), and averaging 5 repetitions on each test (-r 5), the best test result was of 2.08 seconds.
If you don’t specify the number of tests or repetitions, it defaults to 10 loops and 5 repetitions.
However, both the decorator and the timeit module are based on Python. This is why the unix time utility may be useful, as it is an external Python measure.
To run the time utility type:
$ time -p python timing_functions.py
which gives the output:
Total time running random_sort: 1.3931210041 seconds real 1.49 user 1.40 sys 0.08
The first line comes from the decorator we defined, and the other three:
Note: as defined in wikipedia, the kernel is a computer program that manages input/output requests from software, and translates them into data processing instructions for the central processing unit (CPU) and other electronic components of a computer.
Therefore, the difference between the real time and the sum of user+sys may indicate the time spent waiting for input/output or that the system is busy running other external tasks.
If you want to know how much time is spent on each function and method, and how many times each of them is called, you can use the cProfile module:
$ python -m cProfile -s cumulative timing_functions.py
Now you’ll see a detailed description of how many times each function in your code is called, and it will be sorted by the cumulative time spent on each one (thanks to the -s cumulative option).
You’ll see that the total amount of time spent on running your script is higher than before. This is the penalty we pay for measuring the time each function takes to execute.
The line_profiler module gives you information about the CPU time spent on each line in your code.
This module has to be installed first, with
$ pip install line_profiler
Next, you need to specify which functions you want to evaluate using the @profile decorator (you don’t need to import it in your file):
@profile def random_sort2(n): l = [random.random() for i in range(n)] l.sort() return l if __name__ == "__main__": random_sort2(2000000)
Finally, you can obtain a line by line description of the random_sort2 function by typing:
$ kernprof -l -v timing_functions.py
where the -l flag indicates line-by-line and the -v flag indicates verbose output. With this method, we see that the array construction takes about 44% of the computation time, whereas the sort() method takes the remaining 56%.
You will also see that due to the time measurements, the script might take longer to execute.
The memory_profiler module is used to measure memory usage in your code, on a line-by-line basis. However, it can make your code to run much more slower.
Install it with
$ pip install memory_profiler
Also, it is recommended to install the psutil package, so that the memory_profile runs faster:
$ pip install psutil
In a similar way as the line_profiler, use the @profile decorator to mark which functions to track. Next, type:
$ python -m memory_profiler timing_functions.py
yes, the previous script takes longer than the 1 or 2 seconds that took before. And if you didn’t install the psutil package, maybe you’re still waiting for the results!
Looking at the output, note that the memory usage is expressed in terms of MiB, which stand for mebibyte (1MiB = 1.05MB).
Finally, with this package you’ll be able to track how many objects of each type (str, tuple, dict, etc) are created at each stage in your code.
Install it with
$ pip install guppy
Next, add it in your code as:
from guppy import hpy def random_sort3(n): hp = hpy() print "Heap at the beginning of the function\n", hp.heap() l = [random.random() for i in range(n)] l.sort() print "Heap at the end of the function\n", hp.heap() return l if __name__ == "__main__": random_sort3(2000000)
And run your code with:
$ python timing_functions.py
You’ll see something like the following output:
By placing the heap at different places in your code, you can study the object creation and deletion in the script flow.
If you want to learn more about speeding your Python code, I recommend you the book High Performance Python: Practical Performant Programming for Humans, september 2014.
Hope it was useful!
Don’t forget to share it with your friends!
The post 7 tips to Time Python scripts and control Memory & CPU usage appeared first on Marina Mele's site.